diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2014-10-01 12:28:07 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-10-01 13:38:39 -0700 |
commit | 419f0c0f681b76d720699977abe03d29e22db554 (patch) | |
tree | fe326a207ecc55c8103f28a07617eb542411427f /lockfile.c | |
parent | a5e48669a2bb45e3a2a6daf30635270b90056085 (diff) | |
download | git-419f0c0f681b76d720699977abe03d29e22db554.tar.gz |
close_lock_file(): exit (successfully) if file is already closed
Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'lockfile.c')
-rw-r--r-- | lockfile.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lockfile.c b/lockfile.c index f1ce1544d2..d02c3bf901 100644 --- a/lockfile.c +++ b/lockfile.c @@ -233,6 +233,10 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags) int close_lock_file(struct lock_file *lk) { int fd = lk->fd; + + if (fd < 0) + return 0; + lk->fd = -1; return close(fd); } @@ -251,7 +255,7 @@ int commit_lock_file(struct lock_file *lk) { char result_file[PATH_MAX]; size_t i; - if (lk->fd >= 0 && close_lock_file(lk)) + if (close_lock_file(lk)) return -1; strcpy(result_file, lk->filename); i = strlen(result_file) - 5; /* .lock */ |