From afd4066ef7ae1027f9c595de3a06a3e1d20cdb75 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Wed, 12 Nov 2014 12:31:38 +0100 Subject: [PATCH] unlink --- src/CryFuse.cpp | 10 ++++++---- src/cryfs_lib/CryDevice.cpp | 5 +++++ src/cryfs_lib/CryDevice.h | 1 + src/cryfs_lib/CryFile.cpp | 5 +++++ src/cryfs_lib/CryFile.h | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/CryFuse.cpp b/src/CryFuse.cpp index 8cab4910..313d2a8b 100644 --- a/src/CryFuse.cpp +++ b/src/CryFuse.cpp @@ -90,12 +90,14 @@ int CryFuse::mkdir(const path &path, mode_t mode) { } } -//TODO int CryFuse::unlink(const path &path) { //printf("unlink(%s)\n", path.c_str()); - auto real_path = _device->RootDir() / path; - int retstat = ::unlink(real_path.c_str()); - return errcode_map(retstat); + try { + _device->unlink(path); + return 0; + } catch(cryfs::CryErrnoException &e) { + return -e.getErrno(); + } } //TODO diff --git a/src/cryfs_lib/CryDevice.cpp b/src/cryfs_lib/CryDevice.cpp index ad15ff08..bbe4d423 100644 --- a/src/cryfs_lib/CryDevice.cpp +++ b/src/cryfs_lib/CryDevice.cpp @@ -111,3 +111,8 @@ void CryDevice::mkdir(const bf::path &path, mode_t mode) { auto dir = LoadDir(path.parent_path()); dir->createDir(path.filename().native(), mode); } + +void CryDevice::unlink(const bf::path &path) { + auto file = LoadFile(path); + file->unlink(); +} diff --git a/src/cryfs_lib/CryDevice.h b/src/cryfs_lib/CryDevice.h index f47a8638..4835e374 100644 --- a/src/cryfs_lib/CryDevice.h +++ b/src/cryfs_lib/CryDevice.h @@ -35,6 +35,7 @@ public: void access(const bf::path &path, int mask); int createAndOpenFile(const bf::path &path, mode_t mode); void mkdir(const bf::path &path, mode_t mode); + void unlink(const bf::path &path); const bf::path &RootDir() const; private: diff --git a/src/cryfs_lib/CryFile.cpp b/src/cryfs_lib/CryFile.cpp index 2cd2fd95..297a448d 100644 --- a/src/cryfs_lib/CryFile.cpp +++ b/src/cryfs_lib/CryFile.cpp @@ -25,4 +25,9 @@ void CryFile::truncate(off_t size) const { CHECK_RETVAL(retval); } +void CryFile::unlink() { + int retval = ::unlink(base_path().c_str()); + CHECK_RETVAL(retval); +} + } /* namespace cryfs */ diff --git a/src/cryfs_lib/CryFile.h b/src/cryfs_lib/CryFile.h index 13c5f43f..4420368c 100644 --- a/src/cryfs_lib/CryFile.h +++ b/src/cryfs_lib/CryFile.h @@ -18,6 +18,7 @@ public: std::unique_ptr open(int flags) const; void truncate(off_t size) const; + void unlink(); private: DISALLOW_COPY_AND_ASSIGN(CryFile); };