diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-20 15:22:17 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-21 20:38:01 -0500 |
commit | f4b0c2e93a2f45b548465dba84b257bcb3b41446 (patch) | |
tree | b74a6959532ca4ad21c75bd85c348293cfe46e50 /src/operations.cc | |
parent | 60cbb719e7e9b14d4966efcead89bca4fc022c8e (diff) |
Implement unlink
Diffstat (limited to 'src/operations.cc')
-rw-r--r-- | src/operations.cc | 19 |
1 files changed, 19 insertions, 0 deletions
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>(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<Directory>(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; |