Add support for removing files by path
This commit is contained in:
@@ -47,6 +47,8 @@ class FileSystem {
|
||||
|
||||
virtual int remove(uint64_t inode) = 0;
|
||||
|
||||
virtual int remove(const char *path) = 0;
|
||||
|
||||
virtual void resize(uint64_t size = 0) = 0;
|
||||
|
||||
virtual int write(const char *path, void *buffer, uint64_t size, uint8_t fileType = NormalFile) = 0;
|
||||
@@ -146,6 +148,8 @@ class FileSystemTemplate: public FileSystem {
|
||||
|
||||
int remove(uint64_t inode) override;
|
||||
|
||||
int remove(const char *path) override;
|
||||
|
||||
int write(const char *path, void *buffer, uint64_t size, uint8_t fileType = NormalFile) override;
|
||||
|
||||
int write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = NormalFile) override;
|
||||
@@ -297,6 +301,22 @@ uint8_t *FileSystemTemplate<FileStore, FS_TYPE>::read(uint64_t inode, size_t *si
|
||||
#pragma warning(default:4244)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
template<typename FileStore, FsType FS_TYPE>
|
||||
int FileSystemTemplate<FileStore, FS_TYPE>::remove(const char *path) {
|
||||
auto inode = findInodeOf(path);
|
||||
if (inode) {
|
||||
return remove(inode) | rmDirectoryEntry(path);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(default:4244)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
|
||||
@@ -40,3 +40,4 @@ add_test("Test\\ PathIterator::fileName" FSTests PathIterator::fileName)
|
||||
add_test("Test\\ FileSystem32::findInodeOf\\ /" FSTests "FileSystem32::findInodeOf /")
|
||||
add_test("Test\\ FileSystem32::write\\(string\\)" FSTests "FileSystem32::write(string)")
|
||||
add_test("Test\\ FileSystem32::rmDirectoryEntry\\(string\\)" FSTests "FileSystem32::rmDirectoryEntry(string)")
|
||||
add_test("Test\\ FileSystem32::remove\\(string\\)" FSTests "FileSystem32::remove(string)")
|
||||
|
||||
@@ -187,6 +187,38 @@ map<string, int(*)(string)> tests = {
|
||||
delete []buff;
|
||||
delete []dataOut;
|
||||
|
||||
return retval;
|
||||
}
|
||||
},
|
||||
{
|
||||
"FileSystem32::remove(string)",
|
||||
[](string) {
|
||||
int retval = 0;
|
||||
auto path = "/usr/share/test.txt";
|
||||
auto dataIn = "test string";
|
||||
auto dataOutLen = ox_strlen(dataIn) + 1;
|
||||
auto dataOut = new char[dataOutLen];
|
||||
|
||||
const auto size = 1024 * 1024 * 10;
|
||||
auto buff = new uint8_t[size];
|
||||
FileSystem32::format(buff, (FileStore32::FsSize_t) size, true);
|
||||
auto fs = (FileSystem32*) createFileSystem(buff, size);
|
||||
|
||||
retval |= fs->mkdir("/usr");
|
||||
retval |= fs->mkdir("/usr/share");
|
||||
|
||||
retval |= fs->write(path, (void*) dataIn, ox_strlen(dataIn) + 1);
|
||||
retval |= fs->read(path, dataOut, dataOutLen);
|
||||
retval |= ox_strcmp(dataIn, dataOut) != 0;
|
||||
|
||||
retval |= fs->rmDirectoryEntry(path);
|
||||
// the lookup should fail
|
||||
retval |= fs->read(path, dataOut, dataOutLen) == 0;
|
||||
|
||||
delete fs;
|
||||
delete []buff;
|
||||
delete []dataOut;
|
||||
|
||||
return retval;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user