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>
Michael Haggerty committed
Oct 1, 2014 at 12:28 UTC
91f1f1918430f1ee6f9923d949e1543c49f63204
1 file changed
+9
-6
refs.c
+9
-6
@@ -2602,12 +2602,15 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
2602
static int delete_ref_loose(struct ref_lock *lock, int flag)
2603
{
2604
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
2605
- /* loose */
2606
- int err, i = strlen(lock->lk->filename) - LOCK_SUFFIX_LEN;
2607
-
2608
- lock->lk->filename[i] = 0;
2609
- err = unlink_or_warn(lock->lk->filename);
2610
- lock->lk->filename[i] = LOCK_SUFFIX[0];
2605
+ /*
2606
+ * loose. The loose file name is the same as the
2607
+ * lockfile name, minus ".lock":
2608
+ */
2609
+ char *loose_filename = xmemdupz(
2610
+ lock->lk->filename,
2611
+ strlen(lock->lk->filename) - LOCK_SUFFIX_LEN);
2612
+ int err = unlink_or_warn(loose_filename);
2613
+ free(loose_filename);
2614
if (err && errno != ENOENT)
2615
return 1;
2616
}