repack: handle optional files created by pack-objects
We ask pack-objects to pack to a set of temporary files, and then rename them into place. Some files that pack-objects creates may be optional (like a .bitmap file), in which case we would not want to call rename(). We already call stat() and make the chmod optional if the file cannot be accessed. We could simply skip the rename step in this case, but that would be a minor regression in noticing problems with non-optional files (like the .pack and .idx files). Instead, we can now annotate extensions as optional, and skip them if they don't exist (and otherwise rely on rename() to barf). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 21, 2013 at 09:00 UTC
b77fcd1edca58621627d46af0321a9737b1310f0
1 file changed
+7
-2
builtin/repack.c
+7
-2
@@ -117,6 +117,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
117
{
118
struct {
119
const char *name;
120
+ unsigned optional:1;
121
} exts[] = {
122
{".pack"},
123
{".idx"},
@@ -323,6 +324,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
324
for (ext = 0; ext < ARRAY_SIZE(exts); ext++) {
325
char *fname, *fname_old;
326
struct stat statbuffer;
327
+ int exists = 0;
328
fname = mkpathdup("%s/pack-%s%s",
329
packdir, item->string, exts[ext].name);
330
fname_old = mkpathdup("%s-%s%s",
@@ -330,9 +332,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
332
if (!stat(fname_old, &statbuffer)) {
333
statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
334
chmod(fname_old, statbuffer.st_mode);
335
+ exists = 1;
336
+ }
337
+ if (exists || !exts[ext].optional) {
338
+ if (rename(fname_old, fname))
339
+ die_errno(_("renaming '%s' failed"), fname_old);
340
}
334
- if (rename(fname_old, fname))
335
- die_errno(_("renaming '%s' failed"), fname_old);
341
free(fname);
342
free(fname_old);
343
}