Implement renaming
This commit is contained in:
parent
0b2bf1d7b3
commit
7d4618229b
@ -29,13 +29,14 @@ public:
|
||||
std::unique_ptr<blobstore::Blob> LoadBlob(const blockstore::Key &key);
|
||||
void RemoveBlob(const blockstore::Key &key);
|
||||
|
||||
private:
|
||||
blockstore::Key GetOrCreateRootKey(CryConfig *config);
|
||||
blockstore::Key CreateRootBlobAndReturnKey();
|
||||
std::unique_ptr<fspp::Node> Load(const bf::path &path) override;
|
||||
|
||||
std::unique_ptr<DirBlob> LoadDirBlob(const bf::path &path);
|
||||
|
||||
private:
|
||||
blockstore::Key GetOrCreateRootKey(CryConfig *config);
|
||||
blockstore::Key CreateRootBlobAndReturnKey();
|
||||
|
||||
std::unique_ptr<blobstore::BlobStore> _blobStore;
|
||||
|
||||
blockstore::Key _rootKey;
|
||||
|
@ -68,4 +68,8 @@ unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
||||
return children;
|
||||
}
|
||||
|
||||
fspp::Dir::EntryType CryDir::getType() const {
|
||||
return fspp::Dir::EntryType::DIR;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ public:
|
||||
//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;
|
||||
|
||||
fspp::Dir::EntryType getType() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<DirBlob> LoadBlob() const;
|
||||
|
||||
|
@ -43,4 +43,8 @@ void CryFile::truncate(off_t size) const {
|
||||
FileBlob(LoadBlob()).resize(size);
|
||||
}
|
||||
|
||||
fspp::Dir::EntryType CryFile::getType() const {
|
||||
return fspp::Dir::EntryType::FILE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
void stat(struct ::stat *result) const override;
|
||||
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
|
||||
void truncate(off_t size) const override;
|
||||
fspp::Dir::EntryType getType() const override;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -6,12 +6,14 @@
|
||||
#include "CryDir.h"
|
||||
#include "CryFile.h"
|
||||
#include "messmer/fspp/fuse/FuseErrnoException.h"
|
||||
#include <messmer/cpp-utils/pointer.h>
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
using std::unique_ptr;
|
||||
using blockstore::Key;
|
||||
using blobstore::Blob;
|
||||
using cpputils::dynamic_pointer_move;
|
||||
|
||||
//TODO Get rid of this in favor of an exception hierarchy
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
@ -34,7 +36,11 @@ void CryNode::access(int mask) const {
|
||||
}
|
||||
|
||||
void CryNode::rename(const bf::path &to) {
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
//TODO More efficient implementation possible: directly rename when it's actually not moved to a different directory
|
||||
_parent->RemoveChild(_key);
|
||||
_parent->flush();
|
||||
auto targetDir = _device->LoadDirBlob(to.parent_path());
|
||||
targetDir->AddChild(to.filename().native(), _key, getType());
|
||||
}
|
||||
|
||||
void CryNode::utimens(const timespec times[2]) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <messmer/fspp/fs_interface/Node.h>
|
||||
#include "messmer/cpp-utils/macros.h"
|
||||
#include <messmer/fspp/fs_interface/Dir.h>
|
||||
|
||||
#include "CryDevice.h"
|
||||
|
||||
@ -25,6 +26,8 @@ protected:
|
||||
const CryDevice *device() const;
|
||||
std::unique_ptr<blobstore::Blob> LoadBlob() const;
|
||||
|
||||
virtual fspp::Dir::EntryType getType() const = 0;
|
||||
|
||||
private:
|
||||
CryDevice *_device;
|
||||
std::unique_ptr<DirBlob> _parent;
|
||||
|
@ -30,14 +30,13 @@ public:
|
||||
const Entry &GetChild(const std::string &name) const;
|
||||
void AddChildDir(const std::string &name, const blockstore::Key &blobKey);
|
||||
void AddChildFile(const std::string &name, const blockstore::Key &blobKey);
|
||||
void AddChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type);
|
||||
void RemoveChild(const blockstore::Key &key);
|
||||
void flush();
|
||||
|
||||
private:
|
||||
unsigned char magicNumber() const;
|
||||
|
||||
void AddChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type);
|
||||
|
||||
const char *readAndAddNextChild(const char *pos, std::vector<Entry> *result) const;
|
||||
bool hasChild(const std::string &name) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user