Skip to content

Commit fb54abd

Browse files
drafnelgitster
authored andcommitted
fast-import.c: don't try to commit marks file if write failed
We also move the assignment of -1 to the lock file descriptor up, so that rollback_lock_file() can be called safely after a possible attempt to fclose(). This matches the contents of the 'if' statement just above testing success of fdopen(). Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b531394 commit fb54abd

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

fast-import.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,19 +1545,27 @@ static void dump_marks(void)
15451545
return;
15461546
}
15471547

1548-
dump_marks_helper(f, 0, marks);
1549-
if (ferror(f) || fclose(f))
1550-
failure |= error("Unable to write marks file %s: %s",
1551-
mark_file, strerror(errno));
15521548
/*
1553-
* Since the lock file was fdopen()'ed and then fclose()'ed above,
1554-
* assign -1 to the lock file descriptor so that commit_lock_file()
1549+
* Since the lock file was fdopen()'ed, it should not be close()'ed.
1550+
* Assign -1 to the lock file descriptor so that commit_lock_file()
15551551
* won't try to close() it.
15561552
*/
15571553
mark_lock.fd = -1;
1558-
if (commit_lock_file(&mark_lock))
1559-
failure |= error("Unable to write commit file %s: %s",
1554+
1555+
dump_marks_helper(f, 0, marks);
1556+
if (ferror(f) || fclose(f)) {
1557+
rollback_lock_file(&mark_lock);
1558+
failure |= error("Unable to write marks file %s: %s",
15601559
mark_file, strerror(errno));
1560+
return;
1561+
}
1562+
1563+
if (commit_lock_file(&mark_lock)) {
1564+
rollback_lock_file(&mark_lock);
1565+
failure |= error("Unable to commit marks file %s: %s",
1566+
mark_file, strerror(errno));
1567+
return;
1568+
}
15611569
}
15621570

15631571
static int read_next_command(void)

0 commit comments

Comments
 (0)