1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-11-25 04:18:05 +00:00

Add delegate to validate on a file-by-file basis.

This commit is contained in:
Thomas Harte
2025-11-23 12:11:47 -05:00
parent e9ba1c4ede
commit 5c20fcefc4
2 changed files with 21 additions and 1 deletions

View File

@@ -26,11 +26,23 @@ std::optional<std::string> LocalFSFileBundle::key_file() {
return key_file_;
}
void LocalFSFileBundle::set_permission_delegate(PermissionDelegate *const delegate) {
permission_delegate_ = delegate;
}
Storage::FileHolder LocalFSFileBundle::open(const std::string &name, const Storage::FileMode mode) {
return Storage::FileHolder(base_path_ + name, mode);
const auto full_name = base_path_ + name;
if(permission_delegate_) {
permission_delegate_->validate_open(full_name, mode);
}
return Storage::FileHolder(full_name, mode);
}
bool LocalFSFileBundle::erase(const std::string &name) {
const auto full_name = base_path_ + name;
if(permission_delegate_) {
permission_delegate_->validate_erase(full_name);
}
return !remove((base_path_ + name).c_str());
}

View File

@@ -23,11 +23,17 @@ namespace Storage::FileBundle {
bundles in the future.
*/
struct FileBundle {
struct PermissionDelegate {
virtual void validate_open(const std::string &, FileMode) = 0;
virtual void validate_erase(const std::string &) = 0;
};
virtual std::optional<std::string> key_file() = 0;
virtual FileHolder open(const std::string &, FileMode) = 0;
virtual bool erase(const std::string &) = 0;
virtual std::optional<std::string> base_path() = 0;
virtual void set_permission_delegate(PermissionDelegate *) = 0;
};
@@ -39,10 +45,12 @@ struct LocalFSFileBundle: public FileBundle {
bool erase(const std::string &) override;
std::optional<std::string> base_path() override;
void set_permission_delegate(PermissionDelegate *) override;
private:
std::string key_file_;
std::string base_path_;
PermissionDelegate *permission_delegate_ = nullptr;
};
};