libos: Make remove_tree_at use os::Directory
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3e277b5d6f
commit
6c5d6aaf00
@ -1,4 +1,5 @@
|
||||
#include <luna/String.h>
|
||||
#include <os/Directory.h>
|
||||
#include <os/FileSystem.h>
|
||||
|
||||
#include <dirent.h>
|
||||
@ -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<String> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user