From 8092bfef8e572d1d6e6af656dc39b002a3615ae9 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 6 Feb 2016 13:02:21 +0100 Subject: [PATCH] Fix a bug that prevented deleting symlinks. See https://github.com/cryfs/cryfs/issues/2 --- impl/FilesystemImpl.cpp | 23 +++++++++++++++++++++-- impl/FilesystemImpl.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/impl/FilesystemImpl.cpp b/impl/FilesystemImpl.cpp index 6cd876b9..eacaeaa6 100644 --- a/impl/FilesystemImpl.cpp +++ b/impl/FilesystemImpl.cpp @@ -130,6 +130,25 @@ unique_ref FilesystemImpl::LoadSymlink(const bf::path &path) { return std::move(*lnk); } +unique_ref FilesystemImpl::LoadFileOrSymlink(const bf::path &path) { + PROFILE(_loadFileOrSymlinkNanosec); + auto node = _device->Load(path); + if (node == none) { + throw fuse::FuseErrnoException(EIO); + } + auto file = dynamic_pointer_move(*node); + if (file != none) { + return std::move(*file); + } + + auto symlink = dynamic_pointer_move(*node); + if (symlink != none) { + return std::move(*symlink); + } + + throw fuse::FuseErrnoException(EISDIR); +} + int FilesystemImpl::openFile(const bf::path &path, int flags) { auto file = LoadFile(path); return openFile(*file, flags); @@ -249,9 +268,9 @@ void FilesystemImpl::rmdir(const bf::path &path) { void FilesystemImpl::unlink(const bf::path &path) { PROFILE(_unlinkNanosec); - auto file = LoadFile(path); + auto node = LoadFileOrSymlink(path); PROFILE(_unlinkNanosec_withoutLoading); - file->remove(); + node->remove(); } void FilesystemImpl::rename(const bf::path &from, const bf::path &to) { diff --git a/impl/FilesystemImpl.h b/impl/FilesystemImpl.h index f29e4913..f2f41327 100644 --- a/impl/FilesystemImpl.h +++ b/impl/FilesystemImpl.h @@ -51,12 +51,14 @@ private: cpputils::unique_ref LoadFile(const boost::filesystem::path &path); cpputils::unique_ref LoadDir(const boost::filesystem::path &path); cpputils::unique_ref LoadSymlink(const boost::filesystem::path &path); + cpputils::unique_ref LoadFileOrSymlink(const boost::filesystem::path &path); int openFile(const File &file, int flags); #ifdef FSPP_PROFILE std::atomic _loadFileNanosec; std::atomic _loadDirNanosec; std::atomic _loadSymlinkNanosec; + std::atomic _loadFileOrSymlinkNanosec; std::atomic _openFileNanosec; std::atomic _flushNanosec; std::atomic _closeFileNanosec;