use got_path_dirname() in schedule_for_deletion(); avoids const dirname(3) ok naddy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/lib/worktree.c b/lib/worktree.c
index 6d6bd85..a46191b 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3842,7 +3842,7 @@ schedule_for_deletion(void *arg, unsigned char status,
const struct got_error *err = NULL;
struct got_fileindex_entry *ie = NULL;
struct stat sb;
- char *ondisk_path, *parent = NULL;
+ char *ondisk_path;
ie = got_fileindex_entry_get(a->fileindex, relpath, strlen(relpath));
if (ie == NULL)
@@ -3901,6 +3901,8 @@ schedule_for_deletion(void *arg, unsigned char status,
}
if (!a->keep_on_disk && status != GOT_STATUS_MISSING) {
+ size_t root_len;
+
if (dirfd != -1) {
if (unlinkat(dirfd, de_name, 0) != 0) {
err = got_error_from_errno2("unlinkat",
@@ -3912,25 +3914,22 @@ schedule_for_deletion(void *arg, unsigned char status,
goto done;
}
- parent = dirname(ondisk_path);
-
- if (parent == NULL) {
- err = got_error_from_errno2("dirname", ondisk_path);
- goto done;
- }
- while (parent && strcmp(parent, a->worktree->root_path) != 0) {
- if (rmdir(parent) == -1) {
+ root_len = strlen(a->worktree->root_path);
+ do {
+ char *parent;
+ err = got_path_dirname(&parent, ondisk_path);
+ if (err)
+ return err;
+ free(ondisk_path);
+ ondisk_path = parent;
+ if (rmdir(ondisk_path) == -1) {
if (errno != ENOTEMPTY)
err = got_error_from_errno2("rmdir",
- parent);
+ ondisk_path);
break;
}
- parent = dirname(parent);
- if (parent == NULL) {
- err = got_error_from_errno2("dirname", parent);
- goto done;
- }
- }
+ } while (got_path_cmp(ondisk_path, a->worktree->root_path,
+ strlen(ondisk_path), root_len) != 0);
}
got_fileindex_entry_mark_deleted_from_disk(ie);