From f4b0c2e93a2f45b548465dba84b257bcb3b41446 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sat, 20 Feb 2016 15:22:17 -0500 Subject: Implement unlink --- src/operations.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/operations.cc') diff --git a/src/operations.cc b/src/operations.cc index 375a039..ad9f8f3 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -134,6 +134,24 @@ int Release(const char*, fuse_file_info* const file_info) noexcept { return ReleaseResource(file_info->fh); } +int Unlink(const char* c_path) noexcept { + try { + if (std::strcmp(path, "/") == 0) { + // Removing the root is probably a bad idea. + return -EPERM; + } + + // Trim the leading slash so UnlinkAt will treat it relative to root_. + root_->UnlinkAt(path + 1); + return 0; + } catch (const std::system_error& e) { + return -e.code().value(); + } catch (...) { + LOG(ERROR) << "unlink: caught unexpected value"; + return -ENOTRECOVERABLE; + } +} + int Opendir(const char* const path, fuse_file_info* const file_info) noexcept { return OpenResource(path, O_DIRECTORY, 0777, &file_info->fh); } @@ -193,6 +211,7 @@ fuse_operations FuseOperations(File* const root) { result.open = &Open; result.create = &Create; result.release = &Release; + result.unlink = &Unlink; result.opendir = &Opendir; result.readdir = &Readdir; -- cgit v1.2.3