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 <luna/String.h>
|
||||||
|
#include <os/Directory.h>
|
||||||
#include <os/FileSystem.h>
|
#include <os/FileSystem.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@ -60,25 +61,20 @@ namespace os::FileSystem
|
|||||||
if (!rc.has_error()) return {};
|
if (!rc.has_error()) return {};
|
||||||
if (rc.error() != ENOTEMPTY) return rc.release_error();
|
if (rc.error() != ENOTEMPTY) return rc.release_error();
|
||||||
|
|
||||||
DIR* dp = opendir(path.chars());
|
auto dir = TRY(os::Directory::openat(dirfd, path));
|
||||||
if (!dp) return err(errno);
|
|
||||||
|
|
||||||
Vector<String> entries;
|
Vector<String> entries;
|
||||||
|
|
||||||
// FIXME: This is done because the kernel doesn't appreciate us deleting entries while iterating over
|
// 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.
|
// directories. This means that we have to iterate first, then delete.
|
||||||
|
|
||||||
struct dirent* ent;
|
String ent;
|
||||||
while ((ent = readdir(dp)))
|
while ((ent = TRY(dir->next(os::Directory::Filter::ParentAndBase))), !ent.is_empty())
|
||||||
{
|
{
|
||||||
if ("."_sv == ent->d_name || ".."_sv == ent->d_name) continue;
|
TRY(entries.try_append(move(ent)));
|
||||||
auto entry = TRY(String::from_cstring(ent->d_name));
|
|
||||||
TRY(entries.try_append(move(entry)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& entry : entries) { TRY(remove_tree_at(dp->_fd, entry.view())); }
|
for (const auto& entry : entries) { TRY(remove_tree_at(dir->fd(), entry.view())); }
|
||||||
|
|
||||||
closedir(dp);
|
|
||||||
|
|
||||||
return removeat(dirfd, path);
|
return removeat(dirfd, path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user