[ox/fs] Add recursive check on directory remove
This commit is contained in:
parent
40f8af85a8
commit
a1b8de0cb0
11
deps/ox/src/ox/fs/filesystem/types.hpp
vendored
11
deps/ox/src/ox/fs/filesystem/types.hpp
vendored
@ -23,6 +23,17 @@ enum FileType {
|
|||||||
FileType_Directory = 2
|
FileType_Directory = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constexpr const char *toString(FileType t) {
|
||||||
|
switch (t) {
|
||||||
|
case FileType_NormalFile:
|
||||||
|
return "Normal File";
|
||||||
|
case FileType_Directory:
|
||||||
|
return "Directory";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct FileStat {
|
struct FileStat {
|
||||||
uint64_t inode = 0;
|
uint64_t inode = 0;
|
||||||
uint64_t links = 0;
|
uint64_t links = 0;
|
||||||
|
15
deps/ox/src/ox/fs/filesystem2/filesystem.hpp
vendored
15
deps/ox/src/ox/fs/filesystem2/filesystem.hpp
vendored
@ -163,10 +163,17 @@ Error FileSystemTemplate<InodeId_t>::remove(const char *path, bool recursive) {
|
|||||||
auto rootDir = ox_malloca(sizeof(ox::fs::Directory<InodeId_t>), ox::fs::Directory<InodeId_t>, m_fs, fd.value.rootDirInode);
|
auto rootDir = ox_malloca(sizeof(ox::fs::Directory<InodeId_t>), ox::fs::Directory<InodeId_t>, m_fs, fd.value.rootDirInode);
|
||||||
auto inode = rootDir->find(path);
|
auto inode = rootDir->find(path);
|
||||||
oxReturnError(inode.error);
|
oxReturnError(inode.error);
|
||||||
if (auto err = rootDir->remove(path)) {
|
auto st = stat(inode);
|
||||||
// removal failed, try putting the index back
|
oxReturnError(st.error);
|
||||||
oxLogError(rootDir->write(path, inode));
|
if (st.value.fileType == FileType_NormalFile || recursive) {
|
||||||
return err;
|
if (auto err = rootDir->remove(path)) {
|
||||||
|
// removal failed, try putting the index back
|
||||||
|
oxLogError(rootDir->write(path, inode));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
oxTrace("FileSystemTemplate::remove::fail") << "Tried to remove directory without recursive setting.";
|
||||||
|
return OxError(1);
|
||||||
}
|
}
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user