Skip to content

Commit

Permalink
dump_marks(): reimplement using fdopen_lock_file()
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Haggerty <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
mhagger authored and gitster committed Oct 1, 2014
1 parent 013870c commit f70f056
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1794,20 +1794,18 @@ static void dump_marks_helper(FILE *f,
static void dump_marks(void)
{
static struct lock_file mark_lock;
int mark_fd;
FILE *f;

if (!export_marks_file)
return;

mark_fd = hold_lock_file_for_update(&mark_lock, export_marks_file, 0);
if (mark_fd < 0) {
if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
failure |= error("Unable to write marks file %s: %s",
export_marks_file, strerror(errno));
return;
}

f = fdopen(mark_fd, "w");
f = fdopen_lock_file(&mark_lock, "w");
if (!f) {
int saved_errno = errno;
rollback_lock_file(&mark_lock);
Expand All @@ -1816,22 +1814,7 @@ static void dump_marks(void)
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);
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)) {
failure |= error("Unable to commit marks file %s: %s",
export_marks_file, strerror(errno));
Expand Down

0 comments on commit f70f056

Please sign in to comment.