Introduce directory traversal

This commit is contained in:
topjohnwu
2023-06-09 02:00:37 -07:00
parent e13775ec2c
commit 40f25f4d56
9 changed files with 412 additions and 134 deletions

View File

@@ -62,23 +62,6 @@ static walk_result pre_order_walk(int dirfd, const Func &fn) {
return CONTINUE;
}
static void remove_at(int dirfd, struct dirent *entry) {
unlinkat(dirfd, entry->d_name, entry->d_type == DT_DIR ? AT_REMOVEDIR : 0);
}
void rm_rf(const char *path) {
struct stat st;
if (lstat(path, &st) < 0)
return;
if (S_ISDIR(st.st_mode))
frm_rf(xopen(path, O_RDONLY | O_CLOEXEC));
remove(path);
}
void frm_rf(int dirfd) {
post_order_walk(dirfd, remove_at);
}
void mv_path(const char *src, const char *dest) {
file_attr attr;
getattr(src, &attr);