diff --git a/libos/src/FileSystem.cpp b/libos/src/FileSystem.cpp index ba6f3102..a2c1a9a7 100644 --- a/libos/src/FileSystem.cpp +++ b/libos/src/FileSystem.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -60,25 +61,20 @@ namespace os::FileSystem if (!rc.has_error()) return {}; if (rc.error() != ENOTEMPTY) return rc.release_error(); - DIR* dp = opendir(path.chars()); - if (!dp) return err(errno); + auto dir = TRY(os::Directory::openat(dirfd, path)); Vector entries; // FIXME: This is done because the kernel doesn't appreciate us deleting entries while iterating over // directories. This means that we have to iterate first, then delete. - struct dirent* ent; - while ((ent = readdir(dp))) + String ent; + while ((ent = TRY(dir->next(os::Directory::Filter::ParentAndBase))), !ent.is_empty()) { - if ("."_sv == ent->d_name || ".."_sv == ent->d_name) continue; - auto entry = TRY(String::from_cstring(ent->d_name)); - TRY(entries.try_append(move(entry))); + TRY(entries.try_append(move(ent))); } - for (const auto& entry : entries) { TRY(remove_tree_at(dp->_fd, entry.view())); } - - closedir(dp); + for (const auto& entry : entries) { TRY(remove_tree_at(dir->fd(), entry.view())); } return removeat(dirfd, path); }