Fix a bug that prevented deleting symlinks. See https://github.com/cryfs/cryfs/issues/2

This commit is contained in:
Sebastian Messmer 2016-02-06 13:02:21 +01:00
parent c9f0fa781d
commit 8092bfef8e
2 changed files with 23 additions and 2 deletions

View File

@ -130,6 +130,25 @@ unique_ref<Symlink> FilesystemImpl::LoadSymlink(const bf::path &path) {
return std::move(*lnk); return std::move(*lnk);
} }
unique_ref<Node> 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<File>(*node);
if (file != none) {
return std::move(*file);
}
auto symlink = dynamic_pointer_move<Symlink>(*node);
if (symlink != none) {
return std::move(*symlink);
}
throw fuse::FuseErrnoException(EISDIR);
}
int FilesystemImpl::openFile(const bf::path &path, int flags) { int FilesystemImpl::openFile(const bf::path &path, int flags) {
auto file = LoadFile(path); auto file = LoadFile(path);
return openFile(*file, flags); return openFile(*file, flags);
@ -249,9 +268,9 @@ void FilesystemImpl::rmdir(const bf::path &path) {
void FilesystemImpl::unlink(const bf::path &path) { void FilesystemImpl::unlink(const bf::path &path) {
PROFILE(_unlinkNanosec); PROFILE(_unlinkNanosec);
auto file = LoadFile(path); auto node = LoadFileOrSymlink(path);
PROFILE(_unlinkNanosec_withoutLoading); PROFILE(_unlinkNanosec_withoutLoading);
file->remove(); node->remove();
} }
void FilesystemImpl::rename(const bf::path &from, const bf::path &to) { void FilesystemImpl::rename(const bf::path &from, const bf::path &to) {

View File

@ -51,12 +51,14 @@ private:
cpputils::unique_ref<File> LoadFile(const boost::filesystem::path &path); cpputils::unique_ref<File> LoadFile(const boost::filesystem::path &path);
cpputils::unique_ref<Dir> LoadDir(const boost::filesystem::path &path); cpputils::unique_ref<Dir> LoadDir(const boost::filesystem::path &path);
cpputils::unique_ref<Symlink> LoadSymlink(const boost::filesystem::path &path); cpputils::unique_ref<Symlink> LoadSymlink(const boost::filesystem::path &path);
cpputils::unique_ref<Node> LoadFileOrSymlink(const boost::filesystem::path &path);
int openFile(const File &file, int flags); int openFile(const File &file, int flags);
#ifdef FSPP_PROFILE #ifdef FSPP_PROFILE
std::atomic<uint64_t> _loadFileNanosec; std::atomic<uint64_t> _loadFileNanosec;
std::atomic<uint64_t> _loadDirNanosec; std::atomic<uint64_t> _loadDirNanosec;
std::atomic<uint64_t> _loadSymlinkNanosec; std::atomic<uint64_t> _loadSymlinkNanosec;
std::atomic<uint64_t> _loadFileOrSymlinkNanosec;
std::atomic<uint64_t> _openFileNanosec; std::atomic<uint64_t> _openFileNanosec;
std::atomic<uint64_t> _flushNanosec; std::atomic<uint64_t> _flushNanosec;
std::atomic<uint64_t> _closeFileNanosec; std::atomic<uint64_t> _closeFileNanosec;