From: Karsten Blees Date: Tue, 6 Mar 2012 09:18:41 +0000 (+0100) Subject: fix deletion of .git/objects sub-directories in git-prune/repack X-Git-Tag: v1.7.10-rc1~13^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d34e70d6b89b33c398403e872c0dd751d44c7844;p=git.git 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 Reported-by: Stefan Naewe Signed-off-by: Karsten Blees Improved-and-Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c index f9463deec..b58a2e1eb 100644 --- a/builtin/prune-packed.c +++ b/builtin/prune-packed.c @@ -35,8 +35,6 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts) unlink_or_warn(pathname); display_progress(progress, i + 1); } - pathname[len] = 0; - rmdir(pathname); } void prune_packed_objects(int opts) @@ -65,6 +63,8 @@ void prune_packed_objects(int opts) continue; prune_dir(i, d, pathname, len + 3, opts); closedir(d); + pathname[len + 2] = '\0'; + rmdir(pathname); } stop_progress(&progress); } diff --git a/builtin/prune.c b/builtin/prune.c index 58d7cb832..b99b635e4 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -85,9 +85,9 @@ static int prune_dir(int i, char *path) } fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name); } + closedir(dir); if (!show_only) rmdir(path); - closedir(dir); return 0; }