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

Teach fsck and prune about the new location of temporary objects

Since 5723fe7e, temporary objects are now created in their final destination directories, rather than in .git/objects/. Teach fsck to recognize and ignore the temporary objects it encounters, and teach prune to remove them. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Jul 24, 2008 at 17:41 UTC 0e8316cc16f1a938c36f12f5fcae4a081b6ec6ff
2 files changed +28 -17
builtin-fsck.c
+4
@@ -377,6 +377,10 @@ static void fsck_dir(int i, char *path)
377 if (de->d_name[0] != '.')
378 break;
379 continue;
380 + case 14:
381 + if (prefixcmp(de->d_name, "tmp_obj_"))
382 + break;
383 + continue;
384 case 38:
385 sprintf(name, "%02x", i);
386 memcpy(name+2, de->d_name, len+1);
builtin-prune.c
+24 -17
@@ -13,6 +13,22 @@ 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)
17 +{
18 + const char *fullpath = mkpath("%s/%s", path, filename);
19 + if (expire) {
20 + struct stat st;
21 + if (lstat(fullpath, &st))
22 + return error("Could not stat '%s'", fullpath);
23 + if (st.st_mtime > expire)
24 + return 0;
25 + }
26 + printf("Removing stale temporary file %s\n", fullpath);
27 + if (!show_only)
28 + unlink(fullpath);
29 + return 0;
30 +}
31 +
32 static int prune_object(char *path, const char *filename, const unsigned char *sha1)
33 {
34 const char *fullpath = mkpath("%s/%s", path, filename);
@@ -53,6 +69,11 @@ static int prune_dir(int i, char *path)
69 if (de->d_name[0] != '.')
70 break;
71 continue;
72 + case 14:
73 + if (prefixcmp(de->d_name, "tmp_obj_"))
74 + break;
75 + prune_tmp_object(path, de->d_name);
76 + continue;
77 case 38:
78 sprintf(name, "%02x", i);
79 memcpy(name+2, de->d_name, len+1);
@@ -105,23 +126,9 @@ static void remove_temporary_files(void)
126 dirname);
127 return;
128 }
108 - while ((de = readdir(dir)) != NULL) {
109 - if (!prefixcmp(de->d_name, "tmp_")) {
110 - char name[PATH_MAX];
111 - int c = snprintf(name, PATH_MAX, "%s/%s",
112 - dirname, de->d_name);
113 - if (c < 0 || c >= PATH_MAX)
114 - continue;
115 - if (expire) {
116 - struct stat st;
117 - if (stat(name, &st) != 0 || st.st_mtime >= expire)
118 - continue;
119 - }
120 - printf("Removing stale temporary file %s\n", name);
121 - if (!show_only)
122 - unlink(name);
123 - }
124 - }
129 + while ((de = readdir(dir)) != NULL)
130 + if (!prefixcmp(de->d_name, "tmp_"))
131 + prune_tmp_object(dirname, de->d_name);
132 closedir(dir);
133 }
134