Skip to content

Commit db87e39

Browse files
drafnelgitster
authored andcommitted
builtin-prune.c: prune temporary packs in <object_dir>/pack directory
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8b4eb6b commit db87e39

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

builtin-prune.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static const char * const prune_usage[] = {
1313
static int show_only;
1414
static unsigned long expire;
1515

16-
static int prune_tmp_object(char *path, const char *filename)
16+
static int prune_tmp_object(const char *path, const char *filename)
1717
{
1818
const char *fullpath = mkpath("%s/%s", path, filename);
1919
if (expire) {
@@ -110,24 +110,22 @@ static void prune_object_dir(const char *path)
110110
/*
111111
* Write errors (particularly out of space) can result in
112112
* failed temporary packs (and more rarely indexes and other
113-
* files begining with "tmp_") accumulating in the
114-
* object directory.
113+
* files begining with "tmp_") accumulating in the object
114+
* and the pack directories.
115115
*/
116-
static void remove_temporary_files(void)
116+
static void remove_temporary_files(const char *path)
117117
{
118118
DIR *dir;
119119
struct dirent *de;
120-
char* dirname=get_object_directory();
121120

122-
dir = opendir(dirname);
121+
dir = opendir(path);
123122
if (!dir) {
124-
fprintf(stderr, "Unable to open object directory %s\n",
125-
dirname);
123+
fprintf(stderr, "Unable to open directory %s\n", path);
126124
return;
127125
}
128126
while ((de = readdir(dir)) != NULL)
129127
if (!prefixcmp(de->d_name, "tmp_"))
130-
prune_tmp_object(dirname, de->d_name);
128+
prune_tmp_object(path, de->d_name);
131129
closedir(dir);
132130
}
133131

@@ -141,6 +139,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
141139
"expire objects older than <time>"),
142140
OPT_END()
143141
};
142+
char *s;
144143

145144
save_commit_buffer = 0;
146145
init_revisions(&revs, prefix);
@@ -163,6 +162,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
163162
prune_object_dir(get_object_directory());
164163

165164
prune_packed_objects(show_only);
166-
remove_temporary_files();
165+
remove_temporary_files(get_object_directory());
166+
s = xstrdup(mkpath("%s/pack", get_object_directory()));
167+
remove_temporary_files(s);
168+
free(s);
167169
return 0;
168170
}

0 commit comments

Comments
 (0)