parent
d9350e9725
commit
bc024481f9
@ -0,0 +1,311 @@
|
||||
#include "webfuse/filesystem.hpp"
|
||||
|
||||
namespace webfuse
|
||||
{
|
||||
|
||||
filesystem::filesystem(ws_server& server)
|
||||
: proxy(server)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
filesystem::~filesystem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
status filesystem::access(std::string const & path, access_mode mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.access(path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::getattr(std::string const & path, file_attributes & attr)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.getattr(path, attr);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::readlink(std::string const & path, std::string & out)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.readlink(path, out);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::symlink(std::string const & target, std::string const & linkpath)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.symlink(target, linkpath);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::link(std::string const & old_path, std::string const & new_path)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.link(old_path, new_path);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::rename(std::string const & old_path, std::string const & new_path)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.rename(old_path, new_path);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::chmod(std::string const & path, filemode mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.chmod(path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::chown(std::string const & path, user_id uid, group_id gid)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.chown(path, uid, gid);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::truncate(std::string const & path, uint64_t offset, filehandle handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.truncate(path, offset, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::fsync(std::string const & path, bool is_datasync, filehandle handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.fsync(path, is_datasync, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::open(std::string const & path, openflags flags, filehandle & handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.open(path, flags, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::mknod(std::string const & path, filemode mode, uint64_t rdev)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.mknod(path, mode, rdev);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::create(std::string const & path, filemode mode, filehandle & handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.create(path, mode, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::release(std::string const & path, filehandle handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.release(path, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::unlink(std::string const & path)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::read(std::string const & path, char * buffer, size_t buffer_size, uint64_t offset, filehandle handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.read(path, buffer, buffer_size, offset, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::write(std::string const & path, char const * buffer, size_t buffer_size, uint64_t offset, filehandle handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.write(path, buffer, buffer_size, offset, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::mkdir(std::string const & path, filemode mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.mkdir(path, mode);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::readdir(std::string const & path, std::vector<std::string> & entries, filehandle handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.readdir(path, entries, handle);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::rmdir(std::string const & path)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.rmdir(path);
|
||||
}
|
||||
}
|
||||
|
||||
status filesystem::statfs(std::string const & path, filesystem_statistics & statistics)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string req;
|
||||
auto resp = proxy.perform(req).get();
|
||||
return status::bad_enoent;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return fallback.statfs(path, statistics);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
#ifndef WEBFUSE_FILESYSTEM_HPP
|
||||
#define WEBFUSE_FILESYSTEM_HPP
|
||||
|
||||
#include "webfuse/filesystem/filesystem_i.hpp"
|
||||
#include "webfuse/filesystem/empty_filesystem.hpp"
|
||||
#include "webfuse/ws/server.hpp"
|
||||
|
||||
namespace webfuse
|
||||
{
|
||||
|
||||
class filesystem: public filesystem_i
|
||||
{
|
||||
filesystem(filesystem const &) = delete;
|
||||
filesystem& operator=(filesystem const &) = delete;
|
||||
filesystem(filesystem &&) = delete;
|
||||
filesystem& operator=(filesystem &&) = delete;
|
||||
public:
|
||||
explicit filesystem(ws_server& server);
|
||||
~filesystem() override;
|
||||
|
||||
status access(std::string const & path, access_mode mode) override;
|
||||
status getattr(std::string const & path, file_attributes & attr) override;
|
||||
|
||||
status readlink(std::string const & path, std::string & out) override;
|
||||
status symlink(std::string const & target, std::string const & linkpath) override;
|
||||
status link(std::string const & old_path, std::string const & new_path) override;
|
||||
|
||||
status rename(std::string const & old_path, std::string const & new_path) override;
|
||||
status chmod(std::string const & path, filemode mode) override;
|
||||
status chown(std::string const & path, user_id uid, group_id gid) override;
|
||||
status truncate(std::string const & path, uint64_t offset, filehandle handle) override;
|
||||
status fsync(std::string const & path, bool is_datasync, filehandle handle) override;
|
||||
|
||||
status open(std::string const & path, openflags flags, filehandle & handle) override;
|
||||
status mknod(std::string const & path, filemode mode, uint64_t rdev) override;
|
||||
status create(std::string const & path, filemode mode, filehandle & handle) override;
|
||||
status release(std::string const & path, filehandle handle) override;
|
||||
status unlink(std::string const & path) override;
|
||||
|
||||
status read(std::string const & path, char * buffer, size_t buffer_size, uint64_t offset, filehandle handle) override;
|
||||
status write(std::string const & path, char const * buffer, size_t buffer_size, uint64_t offset, filehandle handle) override;
|
||||
|
||||
status mkdir(std::string const & path, filemode mode) override;
|
||||
status readdir(std::string const & path, std::vector<std::string> & entries, filehandle handle) override;
|
||||
status rmdir(std::string const & path) override;
|
||||
|
||||
status statfs(std::string const & path, filesystem_statistics & statistics) override;
|
||||
|
||||
|
||||
private:
|
||||
ws_server &proxy;
|
||||
empty_filesystem fallback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in new issue