summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Brandon Casey <casey@nrlssc.navy.mil>2008-01-17 10:58:34 -0600
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-01-17 22:11:42 -0800
commitfb54abd604080dc2a719934a0a72964a7caf8ff7 (patch)
treede775eebd844628371911b0354f0ce20aca1ff18
parentrefs.c: rework ref_locks by abstracting from underlying struct lock_file (diff)
downloadtgif-fb54abd604080dc2a719934a0a72964a7caf8ff7.tar.xz
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>
-rw-r--r--fast-import.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/fast-import.c b/fast-import.c
index 3609c24288..4cf5092976 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1545,19 +1545,27 @@ static void dump_marks(void)
return;
}
- dump_marks_helper(f, 0, marks);
- if (ferror(f) || fclose(f))
- failure |= error("Unable to write marks file %s: %s",
- mark_file, strerror(errno));
/*
- * Since the lock file was fdopen()'ed and then fclose()'ed above,
- * assign -1 to the lock file descriptor so that commit_lock_file()
+ * Since the lock file was fdopen()'ed, it should not be close()'ed.
+ * Assign -1 to the lock file descriptor so that commit_lock_file()
* won't try to close() it.
*/
mark_lock.fd = -1;
- if (commit_lock_file(&mark_lock))
- failure |= error("Unable to write commit file %s: %s",
+
+ dump_marks_helper(f, 0, marks);
+ if (ferror(f) || fclose(f)) {
+ rollback_lock_file(&mark_lock);
+ failure |= error("Unable to write marks file %s: %s",
mark_file, strerror(errno));
+ return;
+ }
+
+ if (commit_lock_file(&mark_lock)) {
+ rollback_lock_file(&mark_lock);
+ failure |= error("Unable to commit marks file %s: %s",
+ mark_file, strerror(errno));
+ return;
+ }
}
static int read_next_command(void)