diff --git a/deps/ox/src/ox/fs/filesystem/types.hpp b/deps/ox/src/ox/fs/filesystem/types.hpp index c6bab0b6..3f526b9a 100644 --- a/deps/ox/src/ox/fs/filesystem/types.hpp +++ b/deps/ox/src/ox/fs/filesystem/types.hpp @@ -23,6 +23,17 @@ enum FileType { 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 { uint64_t inode = 0; uint64_t links = 0; diff --git a/deps/ox/src/ox/fs/filesystem2/filesystem.hpp b/deps/ox/src/ox/fs/filesystem2/filesystem.hpp index 8219e58e..57ebbbe4 100644 --- a/deps/ox/src/ox/fs/filesystem2/filesystem.hpp +++ b/deps/ox/src/ox/fs/filesystem2/filesystem.hpp @@ -163,10 +163,17 @@ Error FileSystemTemplate::remove(const char *path, bool recursive) { auto rootDir = ox_malloca(sizeof(ox::fs::Directory), ox::fs::Directory, m_fs, fd.value.rootDirInode); auto inode = rootDir->find(path); oxReturnError(inode.error); - if (auto err = rootDir->remove(path)) { - // removal failed, try putting the index back - oxLogError(rootDir->write(path, inode)); - return err; + auto st = stat(inode); + oxReturnError(st.error); + if (st.value.fileType == FileType_NormalFile || recursive) { + 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); }