commit 41a1751cbc65757c0e248a5453a45bc3cdaad3c1
parent a5e971a6d7227f20075302bdd60102f804d65b70
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 9 Mar 2021 15:50:21 -0500
fs: implement rmdirall
Diffstat:
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/fs/fs.ha b/fs/fs.ha
@@ -109,7 +109,29 @@ export fn rmdir(fs: *fs, path: path::path) (void | error) = {
// Removes a directory, and anything in it.
export fn rmdirall(fs: *fs, path: path::path) (void | error) = {
- abort(); // TODO
+ let it = iter(fs, path)?;
+ for (true) match (next(it)) {
+ ent: dirent => {
+ if (path::equal(ent.name, ".")
+ || path::equal(ent.name, "..")) {
+ continue;
+ };
+ switch (ent.ftype) {
+ mode::DIR => {
+ let p = path::join(path, ent.name);
+ defer path::path_free(p);
+ rmdirall(fs, p)?;
+ },
+ * => {
+ let p = path::join(path, ent.name);
+ defer path::path_free(p);
+ remove(fs, p)?;
+ },
+ };
+ },
+ void => break,
+ };
+ return rmdir(fs, path);
};
// Creates a directory and returns a subdir for it. Some filesystems support