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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 5, 2024 at 23:47 UTC
19ace71de05465c690d4eb297bd5d503f8e312b1
1 file changed
+3
-2
builtin/sparse-checkout.c
+3
-2
@@ -338,7 +338,6 @@ static int write_patterns_and_update(struct pattern_list *pl)
338
339
fd = hold_lock_file_for_update(&lk, sparse_filename,
340
LOCK_DIE_ON_ERROR);
341
- free(sparse_filename);
341
342
result = update_working_directory(pl);
343
if (result) {
@@ -355,10 +354,12 @@ static int write_patterns_and_update(struct pattern_list *pl)
354
write_patterns_to_file(fp, pl);
355
356
fflush(fp);
358
- commit_lock_file(&lk);
357
+ if (commit_lock_file(&lk))
358
+ die_errno(_("unable to write %s"), sparse_filename);
359
360
out:
361
clear_pattern_list(pl);
362
+ free(sparse_filename);
363
return result;
364
}
365