@matheusbsbs / matheus-bagliano / commits / fb54abd604
Fork 0

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>

Brandon Casey committed Jan 17, 2008 at 10:58 UTC fb54abd604080dc2a719934a0a72964a7caf8ff7
1 file changed +16 -8
fast-import.c
+16 -8
@@ -1545,19 +1545,27 @@ static void dump_marks(void)
1545 return;
1546 }
1547
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));
1548 /*
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()
1551 * won't try to close() it.
1552 */
1553 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",
1559 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 + }
1569 }
1570
1571 static int read_next_command(void)