@matheusbsbs / matheus-bagliano / commits / db87e3960c
Fork 0

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>

Brandon Casey committed Sep 22, 2008 at 18:34 UTC db87e3960c5a770db13c9ba9602b5e88848e2d1a
1 file changed +12 -10
builtin-prune.c
+12 -10
@@ -13,7 +13,7 @@ static const char * const prune_usage[] = {
13 static int show_only;
14 static unsigned long expire;
15
16 -static int prune_tmp_object(char *path, const char *filename)
16 +static int prune_tmp_object(const char *path, const char *filename)
17 {
18 const char *fullpath = mkpath("%s/%s", path, filename);
19 if (expire) {
@@ -110,24 +110,22 @@ static void prune_object_dir(const char *path)
110 /*
111 * Write errors (particularly out of space) can result in
112 * 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.
115 */
116 -static void remove_temporary_files(void)
116 +static void remove_temporary_files(const char *path)
117 {
118 DIR *dir;
119 struct dirent *de;
120 - char* dirname=get_object_directory();
120
122 - dir = opendir(dirname);
121 + dir = opendir(path);
122 if (!dir) {
124 - fprintf(stderr, "Unable to open object directory %s\n",
125 - dirname);
123 + fprintf(stderr, "Unable to open directory %s\n", path);
124 return;
125 }
126 while ((de = readdir(dir)) != NULL)
127 if (!prefixcmp(de->d_name, "tmp_"))
130 - prune_tmp_object(dirname, de->d_name);
128 + prune_tmp_object(path, de->d_name);
129 closedir(dir);
130 }
131
@@ -141,6 +139,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
139 "expire objects older than <time>"),
140 OPT_END()
141 };
142 + char *s;
143
144 save_commit_buffer = 0;
145 init_revisions(&revs, prefix);
@@ -163,6 +162,9 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
162 prune_object_dir(get_object_directory());
163
164 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);
169 return 0;
170 }