diff --git a/src/ox/fs/filesystem.hpp b/src/ox/fs/filesystem.hpp index d0a671cb1..3fc5cee6c 100644 --- a/src/ox/fs/filesystem.hpp +++ b/src/ox/fs/filesystem.hpp @@ -43,6 +43,11 @@ struct DirectoryListing { } }; +template +bool operator<(const DirectoryListing &a, const DirectoryListing &b) { + return a.name < b.name; +} + template struct __attribute__((packed)) DirectoryEntry { InodeId_t inode; @@ -380,32 +385,36 @@ int FileSystemTemplate::stripDirectories() { template int FileSystemTemplate::mkdir(const char *path) { - Directory dir; - auto err = write(path, &dir, sizeof(dir), FileType::FileType_Directory); - if (err) { - return err; - } + if (!stat(path).inode) { + Directory dir; + auto err = write(path, &dir, sizeof(dir), FileType::FileType_Directory); + if (err) { + return err; + } - // add . entry for self - auto inode = findInodeOf(path); - err = insertDirectoryEntry(path, ".", inode); - if (err) { - remove(inode); - return err; - } + // add . entry for self + auto inode = findInodeOf(path); + err = insertDirectoryEntry(path, ".", inode); + if (err) { + remove(inode); + return err; + } - // add .. entry for parent - size_t pathLen = ox_strlen(path); - char dirPath[pathLen]; - PathIterator pathReader(path, pathLen); - err |= pathReader.dirPath(dirPath, pathLen); - err = insertDirectoryEntry(path, "..", findInodeOf(dirPath)); - if (err) { - remove(inode); - return err; - } + // add .. entry for parent + size_t pathLen = ox_strlen(path); + char dirPath[pathLen]; + PathIterator pathReader(path, pathLen); + err |= pathReader.dirPath(dirPath, pathLen); + err = insertDirectoryEntry(path, "..", findInodeOf(dirPath)); + if (err) { + remove(inode); + return err; + } - return err; + return err; + } else { + return 1; + } } template