This commit is contained in:
Sebastian Messmer 2014-11-12 12:43:49 +01:00
parent a0a30e3c75
commit e561f52dd5
5 changed files with 27 additions and 11 deletions

View File

@ -111,20 +111,22 @@ int CryFuse::rmdir(const path &path) {
//TODO //TODO
int CryFuse::symlink(const path &from, const path &to) { int CryFuse::symlink(const path &from, const path &to) {
//printf("symlink(%s, %s)\n", from.c_str(), to.c_str()); printf("NOT IMPLEMENTED: symlink(%s, %s)\n", from.c_str(), to.c_str());
auto real_from = _device->RootDir() / from; //auto real_from = _device->RootDir() / from;
auto real_to = _device->RootDir() / to; //auto real_to = _device->RootDir() / to;
int retstat = ::symlink(real_from.c_str(), real_to.c_str()); //int retstat = ::symlink(real_from.c_str(), real_to.c_str());
return errcode_map(retstat); //return errcode_map(retstat);
return EIO; //TODO Correct return value
} }
//TODO
int CryFuse::rename(const path &from, const path &to) { int CryFuse::rename(const path &from, const path &to) {
//printf("rename(%s, %s)\n", from.c_str(), to.c_str()); //printf("rename(%s, %s)\n", from.c_str(), to.c_str());
auto real_from = _device->RootDir() / from; try {
auto real_to = _device->RootDir() / to; _device->rename(from, to);
int retstat = ::rename(real_from.c_str(), real_to.c_str()); return 0;
return errcode_map(retstat); } catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
} }
//TODO //TODO

View File

@ -121,3 +121,8 @@ void CryDevice::unlink(const bf::path &path) {
auto file = LoadFile(path); auto file = LoadFile(path);
file->unlink(); file->unlink();
} }
void CryDevice::rename(const bf::path &from, const bf::path &to) {
auto node = Load(from);
node->rename(to);
}

View File

@ -37,6 +37,7 @@ public:
void mkdir(const bf::path &path, mode_t mode); void mkdir(const bf::path &path, mode_t mode);
void rmdir(const bf::path &path); void rmdir(const bf::path &path);
void unlink(const bf::path &path); void unlink(const bf::path &path);
void rename(const bf::path &from, const bf::path &to);
const bf::path &RootDir() const; const bf::path &RootDir() const;
private: private:

View File

@ -22,4 +22,11 @@ void CryNode::access(int mask) const {
CHECK_RETVAL(retval); CHECK_RETVAL(retval);
} }
void CryNode::rename(const bf::path &to) {
auto new_base_path = device()->RootDir() / to;
int retval = ::rename(base_path().c_str(), new_base_path.c_str());
CHECK_RETVAL(retval);
_path = to;
}
} /* namespace cryfs */ } /* namespace cryfs */

View File

@ -19,6 +19,7 @@ public:
void stat(struct ::stat *result) const; void stat(struct ::stat *result) const;
void access(int mask) const; void access(int mask) const;
void rename(const bf::path &to);
protected: protected:
bf::path base_path() const; bf::path base_path() const;
@ -27,7 +28,7 @@ protected:
private: private:
CryDevice *const _device; CryDevice *const _device;
const bf::path _path; bf::path _path;
DISALLOW_COPY_AND_ASSIGN(CryNode); DISALLOW_COPY_AND_ASSIGN(CryNode);
}; };