Create files/dirs owned by the caller
This commit is contained in:
parent
27e376c121
commit
12e802fb7b
@ -32,23 +32,21 @@ CryDir::CryDir(CryDevice *device, unique_ptr<DirBlob> parent, const Key &key)
|
||||
CryDir::~CryDir() {
|
||||
}
|
||||
|
||||
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode) {
|
||||
//TODO Create file owned by calling user (fuse user is given in fuse context)
|
||||
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode, uid_t uid, gid_t gid) {
|
||||
auto blob = LoadBlob();
|
||||
auto child = device()->CreateBlob();
|
||||
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!
|
||||
auto childblob = FileBlob::InitializeEmptyFile(std::move(child));
|
||||
return make_unique<CryOpenFile>(std::move(childblob));
|
||||
}
|
||||
|
||||
void CryDir::createDir(const string &name, mode_t mode) {
|
||||
//TODO Create dir owned by calling user (fuse user is given in fuse context)
|
||||
void CryDir::createDir(const string &name, mode_t mode, uid_t uid, gid_t gid) {
|
||||
auto blob = LoadBlob();
|
||||
auto child = device()->CreateBlob();
|
||||
Key childkey = child->key();
|
||||
blob->AddChildDir(name, childkey, mode);
|
||||
blob->AddChildDir(name, childkey, mode, uid, gid);
|
||||
DirBlob::InitializeEmptyDir(std::move(child), device());
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ public:
|
||||
virtual ~CryDir();
|
||||
|
||||
//TODO return type variance to CryFile/CryDir?
|
||||
std::unique_ptr<fspp::OpenFile> createAndOpenFile(const std::string &name, mode_t mode) override;
|
||||
void createDir(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, 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;
|
||||
|
@ -39,11 +39,14 @@ void CryNode::access(int mask) const {
|
||||
void CryNode::rename(const bf::path &to) {
|
||||
//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.
|
||||
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->flush();
|
||||
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]) {
|
||||
|
@ -125,21 +125,21 @@ bool DirBlob::hasChild(const string &name) const {
|
||||
return found != _entries.end();
|
||||
}
|
||||
|
||||
void DirBlob::AddChildDir(const std::string &name, const Key &blobKey, mode_t mode) {
|
||||
AddChild(name, blobKey, fspp::Dir::EntryType::DIR, 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, uid, gid);
|
||||
}
|
||||
|
||||
void DirBlob::AddChildFile(const std::string &name, const Key &blobKey, mode_t mode) {
|
||||
AddChild(name, blobKey, fspp::Dir::EntryType::FILE, 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, uid, gid);
|
||||
}
|
||||
|
||||
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)) {
|
||||
throw fspp::fuse::FuseErrnoException(EEXIST);
|
||||
}
|
||||
|
||||
_entries.emplace_back(entryType, name, blobKey, mode);
|
||||
_entries.emplace_back(entryType, name, blobKey, mode, uid, gid);
|
||||
_changed = true;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,7 @@ class CryDevice;
|
||||
class DirBlob {
|
||||
public:
|
||||
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_=0, gid_t gid_=0): 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_, gid_t gid_): type(type_), name(name_), key(key_), mode(mode_), uid(uid_), gid(gid_) {
|
||||
switch(type) {
|
||||
case fspp::Dir::EntryType::FILE:
|
||||
mode |= S_IFREG;
|
||||
@ -45,9 +44,9 @@ public:
|
||||
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
|
||||
const Entry &GetChild(const std::string &name) const;
|
||||
const Entry &GetChild(const blockstore::Key &key) const;
|
||||
void AddChildDir(const std::string &name, const blockstore::Key &blobKey, mode_t mode);
|
||||
void AddChildFile(const std::string &name, const blockstore::Key &blobKey, mode_t mode);
|
||||
void AddChild(const std::string &name, const blockstore::Key &blobKey, fspp::Dir::EntryType type, 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, uid_t uid, gid_t gid);
|
||||
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 flush();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user