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

Implement destroy channel.

This commit is contained in:
Thomas Harte
2025-11-22 09:39:05 -05:00
parent 507b81a8a4
commit e2ef3226af
3 changed files with 19 additions and 0 deletions

View File

@@ -128,6 +128,17 @@ void HostFSHandler::perform(const uint8_t function, uint8_t &a, uint16_t &bc, ui
channels_.erase(channel); channels_.erase(channel);
break; break;
// Page 54.
case uint8_t(EXOS::Function::DestroyChannel): {
const auto name = file.name();
channels_.erase(channel);
if(bundle_->erase(name)) {
set_error(EXOS::Error::NoError);
} else {
set_error(EXOS::Error::ProtectionViolation);
}
} break;
// Page 55. // Page 55.
case uint8_t(EXOS::Function::ReadCharacter): { case uint8_t(EXOS::Function::ReadCharacter): {
const auto next = file.get(); const auto next = file.get();

View File

@@ -8,6 +8,8 @@
#include "FileBundle.hpp" #include "FileBundle.hpp"
#include <cstdio>
using namespace Storage::FileBundle; using namespace Storage::FileBundle;
LocalFSFileBundle::LocalFSFileBundle(const std::string &to_contain) { LocalFSFileBundle::LocalFSFileBundle(const std::string &to_contain) {
@@ -27,3 +29,7 @@ std::optional<std::string> LocalFSFileBundle::key_file() {
Storage::FileHolder LocalFSFileBundle::open(const std::string &name, const Storage::FileMode mode) { Storage::FileHolder LocalFSFileBundle::open(const std::string &name, const Storage::FileMode mode) {
return Storage::FileHolder(base_path_ + name, mode); return Storage::FileHolder(base_path_ + name, mode);
} }
bool LocalFSFileBundle::erase(const std::string &name) {
return !remove((base_path_ + name).c_str());
}

View File

@@ -25,6 +25,7 @@ namespace Storage::FileBundle {
struct FileBundle { struct FileBundle {
virtual std::optional<std::string> key_file() = 0; virtual std::optional<std::string> key_file() = 0;
virtual FileHolder open(const std::string &, FileMode) = 0; virtual FileHolder open(const std::string &, FileMode) = 0;
virtual bool erase(const std::string &) = 0;
}; };
@@ -33,6 +34,7 @@ struct LocalFSFileBundle: public FileBundle {
std::optional<std::string> key_file() override; std::optional<std::string> key_file() override;
FileHolder open(const std::string &, FileMode) override; FileHolder open(const std::string &, FileMode) override;
bool erase(const std::string &) override;
private: private:
std::string key_file_; std::string key_file_;