diff --git a/builtin/repack.c b/builtin/repack.c index a176de2f85..8b7dfd043a 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -117,6 +117,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) { struct { const char *name; + unsigned optional:1; } exts[] = { {".pack"}, {".idx"}, @@ -323,6 +324,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) for (ext = 0; ext < ARRAY_SIZE(exts); ext++) { char *fname, *fname_old; struct stat statbuffer; + int exists = 0; fname = mkpathdup("%s/pack-%s%s", packdir, item->string, exts[ext].name); fname_old = mkpathdup("%s-%s%s", @@ -330,9 +332,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (!stat(fname_old, &statbuffer)) { statbuffer.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); chmod(fname_old, statbuffer.st_mode); + exists = 1; + } + if (exists || !exts[ext].optional) { + if (rename(fname_old, fname)) + die_errno(_("renaming '%s' failed"), fname_old); } - if (rename(fname_old, fname)) - die_errno(_("renaming '%s' failed"), fname_old); free(fname); free(fname_old); }