提交 f70f0565 编写于 作者: M Michael Haggerty 提交者: Junio C Hamano

dump_marks(): reimplement using fdopen_lock_file()

Signed-off-by: NMichael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 013870cd
...@@ -1794,20 +1794,18 @@ static void dump_marks_helper(FILE *f, ...@@ -1794,20 +1794,18 @@ static void dump_marks_helper(FILE *f,
static void dump_marks(void) static void dump_marks(void)
{ {
static struct lock_file mark_lock; static struct lock_file mark_lock;
int mark_fd;
FILE *f; FILE *f;
if (!export_marks_file) if (!export_marks_file)
return; return;
mark_fd = hold_lock_file_for_update(&mark_lock, export_marks_file, 0); if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
if (mark_fd < 0) {
failure |= error("Unable to write marks file %s: %s", failure |= error("Unable to write marks file %s: %s",
export_marks_file, strerror(errno)); export_marks_file, strerror(errno));
return; return;
} }
f = fdopen(mark_fd, "w"); f = fdopen_lock_file(&mark_lock, "w");
if (!f) { if (!f) {
int saved_errno = errno; int saved_errno = errno;
rollback_lock_file(&mark_lock); rollback_lock_file(&mark_lock);
...@@ -1816,22 +1814,7 @@ static void dump_marks(void) ...@@ -1816,22 +1814,7 @@ static void dump_marks(void)
return; return;
} }
/*
* 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;
dump_marks_helper(f, 0, marks); dump_marks_helper(f, 0, marks);
if (ferror(f) || fclose(f)) {
int saved_errno = errno;
rollback_lock_file(&mark_lock);
failure |= error("Unable to write marks file %s: %s",
export_marks_file, strerror(saved_errno));
return;
}
if (commit_lock_file(&mark_lock)) { if (commit_lock_file(&mark_lock)) {
failure |= error("Unable to commit marks file %s: %s", failure |= error("Unable to commit marks file %s: %s",
export_marks_file, strerror(errno)); export_marks_file, strerror(errno));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册