Add support for renaming files.

This commit is contained in:
David Given
2023-07-27 23:44:04 +02:00
parent c7d4fee3f6
commit 4eca254daf

View File

@@ -51,9 +51,7 @@ private:
RolandDirent(const std::string& filename)
{
file_type = TYPE_FILE;
this->filename = filename;
path = {filename};
rename(filename);
length = 0;
attributes[Filesystem::FILENAME] = filename;
@@ -62,6 +60,12 @@ private:
attributes[Filesystem::MODE] = "";
}
void rename(const std::string& name)
{
filename = name;
path = {filename};
}
void addBlock(RolandFsFilesystem* fs, uint8_t block)
{
blocks.push_back(block);
@@ -97,7 +101,7 @@ public:
uint32_t capabilities() const override
{
return OP_CREATE | OP_GETFSDATA | OP_LIST | OP_GETFILE | OP_PUTFILE |
OP_GETDIRENT | OP_DELETE;
OP_GETDIRENT | OP_DELETE | OP_MOVE;
}
std::map<std::string, std::string> getMetadata() override
@@ -215,6 +219,19 @@ public:
rewriteDirectory();
}
void moveFile(const Path& oldName, const Path& newName) override
{
mount();
if ((oldName.size() != 1) || (newName.size() != 1))
throw BadPathException();
if (findFileOrReturnNull(newName.front()))
throw BadPathException("File exists");
auto de = findFile(oldName.front());
de->rename(mangleFilename(newName.front()));
rewriteDirectory();
}
private:
void init()
{