sequencer: roll back lock file if write_message() failed
There is no need to wait until the atexit() handler kicks in at the end. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Oct 21, 2016 at 14:26 UTC
4f66c837972a69cc3520e3f7205f44e8833b941a
1 file changed
+7
-3
sequencer.c
+7
-3
@@ -241,10 +241,14 @@ static int write_message(struct strbuf *msgbuf, const char *filename)
241
int msg_fd = hold_lock_file_for_update(&msg_file, filename, 0);
242
if (msg_fd < 0)
243
return error_errno(_("Could not lock '%s'"), filename);
244
- if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0)
245
- return error_errno(_("Could not write to %s"), filename);
246
- if (commit_lock_file(&msg_file) < 0)
244
+ if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0) {
245
+ rollback_lock_file(&msg_file);
246
+ return error_errno(_("Could not write to '%s'"), filename);
247
+ }
248
+ if (commit_lock_file(&msg_file) < 0) {
249
+ rollback_lock_file(&msg_file);
250
return error(_("Error wrapping up %s."), filename);
251
+ }
252
253
return 0;
254
}