summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-10-01 10:28:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-10-01 20:45:11 (GMT)
commit91f1f1918430f1ee6f9923d949e1543c49f63204 (patch)
tree3f894b0d2aa84aa740c7999ea78245b714b76c1b /refs.c
parent7108ad232fc7a4c889e82b40c52125adc9796ff5 (diff)
downloadgit-91f1f1918430f1ee6f9923d949e1543c49f63204.zip
git-91f1f1918430f1ee6f9923d949e1543c49f63204.tar.gz
git-91f1f1918430f1ee6f9923d949e1543c49f63204.tar.bz2
delete_ref_loose(): don't muck around in the lock_file's filename
It's bad manners. Especially since there could be a signal during the call to unlink_or_warn(), in which case the signal handler will see the wrong filename and delete the reference file, leaving the lockfile behind. So make our own copy to work with. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/refs.c b/refs.c
index 73d6bae..a415131 100644
--- a/refs.c
+++ b/refs.c
@@ -2602,12 +2602,15 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
static int delete_ref_loose(struct ref_lock *lock, int flag)
{
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
- /* loose */
- int err, i = strlen(lock->lk->filename) - LOCK_SUFFIX_LEN;
-
- lock->lk->filename[i] = 0;
- err = unlink_or_warn(lock->lk->filename);
- lock->lk->filename[i] = LOCK_SUFFIX[0];
+ /*
+ * loose. The loose file name is the same as the
+ * lockfile name, minus ".lock":
+ */
+ char *loose_filename = xmemdupz(
+ lock->lk->filename,
+ strlen(lock->lk->filename) - LOCK_SUFFIX_LEN);
+ int err = unlink_or_warn(loose_filename);
+ free(loose_filename);
if (err && errno != ENOENT)
return 1;
}