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 <john0312@gmail.com> Reported-by: Stefan Naewe <stefan.naewe@gmail.com> Signed-off-by: Karsten Blees <blees@dcon.de> Improved-and-Acked-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karsten Blees committed
Mar 6, 2012 at 10:18 UTC
d34e70d6b89b33c398403e872c0dd751d44c7844
2 files changed
+3
-3
builtin/prune-packed.c
+2
-2
@@ -35,8 +35,6 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
35
unlink_or_warn(pathname);
36
display_progress(progress, i + 1);
37
}
38
- pathname[len] = 0;
39
- rmdir(pathname);
38
}
39
40
void prune_packed_objects(int opts)
@@ -65,6 +63,8 @@ void prune_packed_objects(int opts)
63
continue;
64
prune_dir(i, d, pathname, len + 3, opts);
65
closedir(d);
66
+ pathname[len + 2] = '\0';
67
+ rmdir(pathname);
68
}
69
stop_progress(&progress);
70
}
builtin/prune.c
+1
-1
@@ -85,9 +85,9 @@ static int prune_dir(int i, char *path)
85
}
86
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
87
}
88
+ closedir(dir);
89
if (!show_only)
90
rmdir(path);
90
- closedir(dir);
91
return 0;
92
}
93