Skip to content

Commit 19ace71

Browse files
peffgitster
authored andcommitted
sparse-checkout: check commit_lock_file when writing patterns
When writing a new "sparse-checkout" file, we do the usual strategy of writing to a lockfile and committing it into place. But we don't check the outcome of commit_lock_file(). Failing there would prevent us from writing a bogus file (good), but we would ignore the error and return a successful exit code (bad). Fix this by calling die(). Note that we need to keep the sparse_filename variable valid for longer, since the filename stored in the lock_file struct will be dropped when we run commit_lock_file(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d39cc71 commit 19ace71

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/sparse-checkout.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ static int write_patterns_and_update(struct pattern_list *pl)
338338

339339
fd = hold_lock_file_for_update(&lk, sparse_filename,
340340
LOCK_DIE_ON_ERROR);
341-
free(sparse_filename);
342341

343342
result = update_working_directory(pl);
344343
if (result) {
@@ -355,10 +354,12 @@ static int write_patterns_and_update(struct pattern_list *pl)
355354
write_patterns_to_file(fp, pl);
356355

357356
fflush(fp);
358-
commit_lock_file(&lk);
357+
if (commit_lock_file(&lk))
358+
die_errno(_("unable to write %s"), sparse_filename);
359359

360360
out:
361361
clear_pattern_list(pl);
362+
free(sparse_filename);
362363
return result;
363364
}
364365

0 commit comments

Comments
 (0)