Create files/dirs owned by the caller

This commit is contained in:
Sebastian Messmer 2015-04-22 14:32:03 +02:00
parent 27e376c121
commit 12e802fb7b
5 changed files with 21 additions and 21 deletions

View File

@ -32,23 +32,21 @@ CryDir::CryDir(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
CryDir::~CryDir() { CryDir::~CryDir() {
} }
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode) { unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode, uid_t uid, gid_t gid) {
//TODO Create file owned by calling user (fuse user is given in fuse context)
auto blob = LoadBlob(); auto blob = LoadBlob();
auto child = device()->CreateBlob(); auto child = device()->CreateBlob();
Key childkey = child->key(); Key childkey = child->key();
blob->AddChildFile(name, childkey, mode); blob->AddChildFile(name, childkey, mode, uid, gid);
//TODO Do we need a return value in createDir for fspp? If not, change fspp Dir interface! //TODO Do we need a return value in createDir for fspp? If not, change fspp Dir interface!
auto childblob = FileBlob::InitializeEmptyFile(std::move(child)); auto childblob = FileBlob::InitializeEmptyFile(std::move(child));
return make_unique<CryOpenFile>(std::move(childblob)); return make_unique<CryOpenFile>(std::move(childblob));
} }
void CryDir::createDir(const string &name, mode_t mode) { void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) {
//TODO Create dir owned by calling user (fuse user is given in fuse context)
auto blob = LoadBlob(); auto blob = LoadBlob();
auto child = device()->CreateBlob(); auto child = device()->CreateBlob();
Key childkey = child->key(); Key childkey = child->key();
blob->AddChildDir(name, childkey, mode); blob->AddChildDir(name, childkey, mode, uid, gid);
DirBlob::InitializeEmptyDir(std::move(child), device()); DirBlob::InitializeEmptyDir(std::move(child), device());
} }

View File

@ -14,8 +14,8 @@ public:
virtual ~CryDir(); virtual ~CryDir();
//TODO return type variance to CryFile/CryDir? //TODO return type variance to CryFile/CryDir?
std::unique_ptr<fspp::OpenFile> createAndOpenFile(const std::string &name, mode_t mode) override; std::unique_ptr<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) override; void createDir(const std::string &name, mode_t mode, uid_t uid, gid_t gid) override;
//TODO Make Entry a public class instead of hidden in DirBlob (which is not publicly visible) //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; std::unique_ptr<std::vector<fspp::Dir::Entry>> children() const override;

View File

@ -39,11 +39,14 @@ void CryNode::access(int mask) const {
void CryNode::rename(const bf::path &to) { void CryNode::rename(const bf::path &to) {
//TODO More efficient implementation possible: directly rename when it's actually not moved to a different directory //TODO More efficient implementation possible: directly rename when it's actually not moved to a different directory
// It's also quite ugly code because in the parent==targetDir case, it depends on _parent not overriding the changes made by targetDir. // It's also quite ugly code because in the parent==targetDir case, it depends on _parent not overriding the changes made by targetDir.
mode_t mode = _parent->GetChild(_key).mode; auto old = _parent->GetChild(_key);
auto mode = old.mode;
auto uid = old.uid;
auto gid = old.gid;
_parent->RemoveChild(_key); _parent->RemoveChild(_key);
_parent->flush(); _parent->flush();
auto targetDir = _device->LoadDirBlob(to.parent_path()); auto targetDir = _device->LoadDirBlob(to.parent_path());
targetDir->AddChild(to.filename().native(), _key, getType(), mode); targetDir->AddChild(to.filename().native(), _key, getType(), mode, uid, gid);
} }
void CryNode::utimens(const timespec times[2]) { void CryNode::utimens(const timespec times[2]) {

View File

@ -125,21 +125,21 @@ bool DirBlob::hasChild(const string &name) const {
return found != _entries.end(); return found != _entries.end();
} }
void DirBlob::AddChildDir(const std::string &name, const Key &blobKey, mode_t mode) { void DirBlob::AddChildDir(const std::string &name, const Key &blobKey, mode_t mode, uid_t uid, gid_t gid) {
AddChild(name, blobKey, fspp::Dir::EntryType::DIR, mode); AddChild(name, blobKey, fspp::Dir::EntryType::DIR, mode, uid, gid);
} }
void DirBlob::AddChildFile(const std::string &name, const Key &blobKey, mode_t mode) { void DirBlob::AddChildFile(const std::string &name, const Key &blobKey, mode_t mode, uid_t uid, gid_t gid) {
AddChild(name, blobKey, fspp::Dir::EntryType::FILE, mode); AddChild(name, blobKey, fspp::Dir::EntryType::FILE, mode, uid, gid);
} }
void DirBlob::AddChild(const std::string &name, const Key &blobKey, void DirBlob::AddChild(const std::string &name, const Key &blobKey,
fspp::Dir::EntryType entryType, mode_t mode) { fspp::Dir::EntryType entryType, mode_t mode, uid_t uid, gid_t gid) {
if (hasChild(name)) { if (hasChild(name)) {
throw fspp::fuse::FuseErrnoException(EEXIST); throw fspp::fuse::FuseErrnoException(EEXIST);
} }
_entries.emplace_back(entryType, name, blobKey, mode); _entries.emplace_back(entryType, name, blobKey, mode, uid, gid);
_changed = true; _changed = true;
} }

View File

@ -16,8 +16,7 @@ class CryDevice;
class DirBlob { class DirBlob {
public: public:
struct Entry { struct Entry {
//TODO Remove default value for parameters uid_ and gid_ and instead pass them in Entry(fspp::Dir::EntryType type_, const std::string &name_, const blockstore::Key &key_, mode_t mode_, uid_t uid_, gid_t gid_): type(type_), name(name_), key(key_), mode(mode_), uid(uid_), gid(gid_) {
Entry(fspp::Dir::EntryType type_, const std::string &name_, const blockstore::Key &key_, mode_t mode_, uid_t uid_=0, gid_t gid_=0): type(type_), name(name_), key(key_), mode(mode_), uid(uid_), gid(gid_) {
switch(type) { switch(type) {
case fspp::Dir::EntryType::FILE: case fspp::Dir::EntryType::FILE:
mode |= S_IFREG; mode |= S_IFREG;
@ -45,9 +44,9 @@ public:
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const; void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
const Entry &GetChild(const std::string &name) const; const Entry &GetChild(const std::string &name) const;
const Entry &GetChild(const blockstore::Key &key) const; const Entry &GetChild(const blockstore::Key &key) const;
void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode); void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid);
void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode); void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode, uid_t uid, gid_t gid);
void AddChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, mode_t mode); void AddChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, mode_t mode, uid_t uid, gid_t gid);
void RemoveChild(const blockstore::Key &key); void RemoveChild(const blockstore::Key &key);
void flush(); void flush();