Adapt to new fspp interface using unique_ref instead of unique_ptr

This commit is contained in:
Sebastian Meßmer 2015-06-18 19:36:05 +02:00
parent e883bc5747
commit 2f22cbc9a8
8 changed files with 24 additions and 24 deletions

View File

@ -68,26 +68,26 @@ Key CryDevice::CreateRootBlobAndReturnKey() {
CryDevice::~CryDevice() {
}
unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
optional<unique_ref<fspp::Node>> CryDevice::Load(const bf::path &path) {
assert(path.is_absolute());
if (path.parent_path().empty()) {
//We are asked to load the root directory '/'.
return make_unique<CryDir>(this, none, _rootKey);
return optional<unique_ref<fspp::Node>>(make_unique_ref<CryDir>(this, none, _rootKey));
}
auto parent = LoadDirBlob(path.parent_path());
if (parent == none) {
//TODO Return correct fuse error
return nullptr;
return none;
}
auto entry = (*parent)->GetChild(path.filename().native());
if (entry.type == fspp::Dir::EntryType::DIR) {
return make_unique<CryDir>(this, std::move(*parent), entry.key);
return optional<unique_ref<fspp::Node>>(make_unique_ref<CryDir>(this, std::move(*parent), entry.key));
} else if (entry.type == fspp::Dir::EntryType::FILE) {
return make_unique<CryFile>(this, std::move(*parent), entry.key);
return optional<unique_ref<fspp::Node>>(make_unique_ref<CryFile>(this, std::move(*parent), entry.key));
} else if (entry.type == fspp::Dir::EntryType::SYMLINK) {
return make_unique<CrySymlink>(this, std::move(*parent), entry.key);
return optional<unique_ref<fspp::Node>>(make_unique_ref<CrySymlink>(this, std::move(*parent), entry.key));
} else {
throw FuseErrnoException(EIO);
}

View File

@ -29,7 +29,7 @@ public:
boost::optional<cpputils::unique_ref<blobstore::Blob>> LoadBlob(const blockstore::Key &key);
void RemoveBlob(const blockstore::Key &key);
std::unique_ptr<fspp::Node> Load(const boost::filesystem::path &path) override;
boost::optional<cpputils::unique_ref<fspp::Node>> Load(const boost::filesystem::path &path) override;
boost::optional<cpputils::unique_ref<DirBlob>> LoadDirBlob(const boost::filesystem::path &path);

View File

@ -37,7 +37,7 @@ CryDir::CryDir(CryDevice *device, boost::optional<unique_ref<DirBlob>> parent, c
CryDir::~CryDir() {
}
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode, uid_t uid, gid_t gid) {
unique_ref<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode, uid_t uid, gid_t gid) {
auto blob = LoadBlob();
if (blob == none) {
//TODO Return correct fuse error
@ -48,7 +48,7 @@ unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t
(*blob)->AddChildFile(name, childkey, mode, uid, gid);
//TODO Do we need a return value in createDir for fspp? If not, change fspp Dir interface!
auto childblob = FileBlob::InitializeEmptyFile(std::move(child));
return make_unique<CryOpenFile>(std::move(childblob));
return make_unique_ref<CryOpenFile>(std::move(childblob));
}
void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) {
@ -72,8 +72,8 @@ optional<unique_ref<DirBlob>> CryDir::LoadBlob() const {
return make_unique_ref<DirBlob>(std::move(*blob), const_cast<CryDevice*>(device()));
}
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
auto children = make_unique<vector<fspp::Dir::Entry>>();
unique_ref<vector<fspp::Dir::Entry>> CryDir::children() const {
auto children = make_unique_ref<vector<fspp::Dir::Entry>>();
children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, "."));
children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, ".."));
auto blob = LoadBlob();

View File

@ -14,12 +14,12 @@ public:
virtual ~CryDir();
//TODO return type variance to CryFile/CryDir?
std::unique_ptr<fspp::OpenFile> createAndOpenFile(const std::string &name, mode_t mode, uid_t uid, gid_t gid) override;
cpputils::unique_ref<fspp::OpenFile> createAndOpenFile(const std::string &name, mode_t mode, uid_t uid, gid_t gid) override;
void createDir(const std::string &name, mode_t mode, uid_t uid, gid_t gid) override;
void createSymlink(const std::string &name, const boost::filesystem::path &target, uid_t uid, gid_t gid) override;
//TODO Make Entry a public class instead of hidden in DirBlob (which is not publicly visible)
std::unique_ptr<std::vector<fspp::Dir::Entry>> children() const override;
cpputils::unique_ref<std::vector<fspp::Dir::Entry>> children() const override;
fspp::Dir::EntryType getType() const override;

View File

@ -28,10 +28,10 @@ CryFile::CryFile(CryDevice *device, unique_ref<DirBlob> parent, const Key &key)
CryFile::~CryFile() {
}
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
unique_ref<fspp::OpenFile> CryFile::open(int flags) const {
auto blob = LoadBlob();
assert(blob != none);
return make_unique<CryOpenFile>(make_unique_ref<FileBlob>(std::move(*blob)));
return make_unique_ref<CryOpenFile>(make_unique_ref<FileBlob>(std::move(*blob)));
}
void CryFile::truncate(off_t size) const {

View File

@ -14,7 +14,7 @@ public:
CryFile(CryDevice *device, cpputils::unique_ref<DirBlob> parent, const blockstore::Key &key);
virtual ~CryFile();
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
cpputils::unique_ref<fspp::OpenFile> open(int flags) const override;
void truncate(off_t size) const override;
fspp::Dir::EntryType getType() const override;

View File

@ -33,7 +33,7 @@ TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
}
CryDevice dev(std::move(CryConfigLoader::loadExisting(config.path()).get()), make_unique<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root)->children();
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}
TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
@ -42,7 +42,7 @@ TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
}
CryDevice dev(std::move(CryConfigLoader::loadExisting(config.path()).get()), make_unique<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root)->children();
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}
TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
@ -51,5 +51,5 @@ TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
}
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
auto root = dev.Load(bf::path("/"));
dynamic_pointer_move<CryDir>(root)->children();
dynamic_pointer_move<CryDir>(root.get()).get()->children();
}

View File

@ -4,8 +4,8 @@
#include "../src/CryDevice.h"
using std::unique_ptr;
using std::make_unique;
using cpputils::unique_ref;
using cpputils::make_unique_ref;
using fspp::Device;
@ -19,10 +19,10 @@ public:
// Don't create config tempfile yet
: configFile(false) {}
unique_ptr<Device> createDevice() override {
auto blockStore = make_unique<FakeBlockStore>();
unique_ref<Device> createDevice() override {
auto blockStore = std::make_unique<FakeBlockStore>();
auto config = CryConfigLoader::loadOrCreateWithWeakKey(configFile.path());
return make_unique<CryDevice>(std::move(config), std::move(blockStore));
return make_unique_ref<CryDevice>(std::move(config), std::move(blockStore));
}
cpputils::TempFile configFile;