Skip to content

Commit d34e70d

Browse files
Karsten Bleesgitster
authored andcommitted
fix deletion of .git/objects sub-directories in git-prune/repack
Both git-prune and git-repack (and thus, git-gc) try to rmdir while holding a DIR* handle on the directory. This can leave dangling empty directories in the .git/objects on platforms where directory cannot be removed while they are open. First call closedir() and then rmdir(); that is more logical ordering. Reported-by: John Chen <[email protected]> Reported-by: Stefan Naewe <[email protected]> Signed-off-by: Karsten Blees <[email protected]> Improved-and-Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0dbe659 commit d34e70d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

builtin/prune-packed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
3535
unlink_or_warn(pathname);
3636
display_progress(progress, i + 1);
3737
}
38-
pathname[len] = 0;
39-
rmdir(pathname);
4038
}
4139

4240
void prune_packed_objects(int opts)
@@ -65,6 +63,8 @@ void prune_packed_objects(int opts)
6563
continue;
6664
prune_dir(i, d, pathname, len + 3, opts);
6765
closedir(d);
66+
pathname[len + 2] = '\0';
67+
rmdir(pathname);
6868
}
6969
stop_progress(&progress);
7070
}

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ static int prune_dir(int i, char *path)
8585
}
8686
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
8787
}
88+
closedir(dir);
8889
if (!show_only)
8990
rmdir(path);
90-
closedir(dir);
9191
return 0;
9292
}
9393

0 commit comments

Comments
 (0)