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>
int close_lock_file(struct lock_file *lk)
{
int fd = lk->fd;
+
+ if (fd < 0)
+ return 0;
+
lk->fd = -1;
return close(fd);
}
{
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 */
static int commit_locked_index(struct lock_file *lk)
{
if (alternate_index_output) {
- if (lk->fd >= 0 && close_lock_file(lk))
+ if (close_lock_file(lk))
return -1;
if (rename(lk->filename, alternate_index_output))
return -1;