[PATCH v6 12/39] delete_ref_loose(): don't muck around in the lock_file's filename
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Sep 26, 2014, 10:08 UTC
- Message-ID
- <1411726119-31598-13-git-send-email-mhagger@alum.mit.edu>
- In-Reply-To
- <1411726119-31598-1-git-send-email-mhagger@alum.mit.edu>
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> --- refs.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/refs.c b/refs.c index 53cd4fb..11c76ec 100644 --- a/refs.c +++ b/refs.c @@ -2551,12 +2551,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; }
-- 2.1.0