From 2f22cbc9a87dd8b933b37a3b135d9acff596a594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Me=C3=9Fmer?= Date: Thu, 18 Jun 2015 19:36:05 +0200 Subject: [PATCH] Adapt to new fspp interface using unique_ref instead of unique_ptr --- src/CryDevice.cpp | 12 ++++++------ src/CryDevice.h | 2 +- src/CryDir.cpp | 8 ++++---- src/CryDir.h | 4 ++-- src/CryFile.cpp | 4 ++-- src/CryFile.h | 2 +- test/CryFsTest.cpp | 6 +++--- test/FileSystemTest.cpp | 10 +++++----- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/CryDevice.cpp b/src/CryDevice.cpp index 36be5538..4592b029 100644 --- a/src/CryDevice.cpp +++ b/src/CryDevice.cpp @@ -68,26 +68,26 @@ Key CryDevice::CreateRootBlobAndReturnKey() { CryDevice::~CryDevice() { } -unique_ptr CryDevice::Load(const bf::path &path) { +optional> 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(this, none, _rootKey); + return optional>(make_unique_ref(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(this, std::move(*parent), entry.key); + return optional>(make_unique_ref(this, std::move(*parent), entry.key)); } else if (entry.type == fspp::Dir::EntryType::FILE) { - return make_unique(this, std::move(*parent), entry.key); + return optional>(make_unique_ref(this, std::move(*parent), entry.key)); } else if (entry.type == fspp::Dir::EntryType::SYMLINK) { - return make_unique(this, std::move(*parent), entry.key); + return optional>(make_unique_ref(this, std::move(*parent), entry.key)); } else { throw FuseErrnoException(EIO); } diff --git a/src/CryDevice.h b/src/CryDevice.h index 38b7b47b..ac93222c 100644 --- a/src/CryDevice.h +++ b/src/CryDevice.h @@ -29,7 +29,7 @@ public: boost::optional> LoadBlob(const blockstore::Key &key); void RemoveBlob(const blockstore::Key &key); - std::unique_ptr Load(const boost::filesystem::path &path) override; + boost::optional> Load(const boost::filesystem::path &path) override; boost::optional> LoadDirBlob(const boost::filesystem::path &path); diff --git a/src/CryDir.cpp b/src/CryDir.cpp index f42086ee..69755c87 100644 --- a/src/CryDir.cpp +++ b/src/CryDir.cpp @@ -37,7 +37,7 @@ CryDir::CryDir(CryDevice *device, boost::optional> parent, c CryDir::~CryDir() { } -unique_ptr CryDir::createAndOpenFile(const string &name, mode_t mode, uid_t uid, gid_t gid) { +unique_ref 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 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(std::move(childblob)); + return make_unique_ref(std::move(childblob)); } void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) { @@ -72,8 +72,8 @@ optional> CryDir::LoadBlob() const { return make_unique_ref(std::move(*blob), const_cast(device())); } -unique_ptr> CryDir::children() const { - auto children = make_unique>(); +unique_ref> CryDir::children() const { + auto children = make_unique_ref>(); children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, ".")); children->push_back(fspp::Dir::Entry(fspp::Dir::EntryType::DIR, "..")); auto blob = LoadBlob(); diff --git a/src/CryDir.h b/src/CryDir.h index 2a814c59..ca578ffd 100644 --- a/src/CryDir.h +++ b/src/CryDir.h @@ -14,12 +14,12 @@ public: virtual ~CryDir(); //TODO return type variance to CryFile/CryDir? - std::unique_ptr createAndOpenFile(const std::string &name, mode_t mode, uid_t uid, gid_t gid) override; + cpputils::unique_ref 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> children() const override; + cpputils::unique_ref> children() const override; fspp::Dir::EntryType getType() const override; diff --git a/src/CryFile.cpp b/src/CryFile.cpp index da3cf853..e074b9f7 100644 --- a/src/CryFile.cpp +++ b/src/CryFile.cpp @@ -28,10 +28,10 @@ CryFile::CryFile(CryDevice *device, unique_ref parent, const Key &key) CryFile::~CryFile() { } -unique_ptr CryFile::open(int flags) const { +unique_ref CryFile::open(int flags) const { auto blob = LoadBlob(); assert(blob != none); - return make_unique(make_unique_ref(std::move(*blob))); + return make_unique_ref(make_unique_ref(std::move(*blob))); } void CryFile::truncate(off_t size) const { diff --git a/src/CryFile.h b/src/CryFile.h index 7fef5820..e1db2cff 100644 --- a/src/CryFile.h +++ b/src/CryFile.h @@ -14,7 +14,7 @@ public: CryFile(CryDevice *device, cpputils::unique_ref parent, const blockstore::Key &key); virtual ~CryFile(); - std::unique_ptr open(int flags) const override; + cpputils::unique_ref open(int flags) const override; void truncate(off_t size) const override; fspp::Dir::EntryType getType() const override; diff --git a/test/CryFsTest.cpp b/test/CryFsTest.cpp index 6546aa72..c8d658e3 100644 --- a/test/CryFsTest.cpp +++ b/test/CryFsTest.cpp @@ -33,7 +33,7 @@ TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) { } CryDevice dev(std::move(CryConfigLoader::loadExisting(config.path()).get()), make_unique(rootdir.path())); auto root = dev.Load(bf::path("/")); - dynamic_pointer_move(root)->children(); + dynamic_pointer_move(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(rootdir.path())); auto root = dev.Load(bf::path("/")); - dynamic_pointer_move(root)->children(); + dynamic_pointer_move(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(rootdir.path())); auto root = dev.Load(bf::path("/")); - dynamic_pointer_move(root)->children(); + dynamic_pointer_move(root.get()).get()->children(); } diff --git a/test/FileSystemTest.cpp b/test/FileSystemTest.cpp index 4dd28b26..e8242a6b 100644 --- a/test/FileSystemTest.cpp +++ b/test/FileSystemTest.cpp @@ -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 createDevice() override { - auto blockStore = make_unique(); + unique_ref createDevice() override { + auto blockStore = std::make_unique(); auto config = CryConfigLoader::loadOrCreateWithWeakKey(configFile.path()); - return make_unique(std::move(config), std::move(blockStore)); + return make_unique_ref(std::move(config), std::move(blockStore)); } cpputils::TempFile configFile;