mirror of
https://github.com/git/git
synced 2024-11-04 16:17:49 +00:00
lockfile: report when rollback fails
We do not report to the caller when rolling back a lockfile fails, which will be needed by the reftable compaction logic in a subsequent commit. It also cannot really report on all errors because the function calls `delete_tempfile()`, which doesn't return an error either. Refactor the code so that both `delete_tempfile()` and `rollback_lock_file()` return an error code. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
b387623c12
commit
4ae540d421
3 changed files with 17 additions and 12 deletions
|
@ -321,11 +321,11 @@ static inline int commit_lock_file_to(struct lock_file *lk, const char *path)
|
|||
* Roll back `lk`: close the file descriptor and/or file pointer and
|
||||
* remove the lockfile. It is a NOOP to call `rollback_lock_file()`
|
||||
* for a `lock_file` object that has already been committed or rolled
|
||||
* back.
|
||||
* back. No error will be returned in this case.
|
||||
*/
|
||||
static inline void rollback_lock_file(struct lock_file *lk)
|
||||
static inline int rollback_lock_file(struct lock_file *lk)
|
||||
{
|
||||
delete_tempfile(&lk->tempfile);
|
||||
return delete_tempfile(&lk->tempfile);
|
||||
}
|
||||
|
||||
#endif /* LOCKFILE_H */
|
||||
|
|
21
tempfile.c
21
tempfile.c
|
@ -50,15 +50,17 @@
|
|||
|
||||
static VOLATILE_LIST_HEAD(tempfile_list);
|
||||
|
||||
static void remove_template_directory(struct tempfile *tempfile,
|
||||
static int remove_template_directory(struct tempfile *tempfile,
|
||||
int in_signal_handler)
|
||||
{
|
||||
if (tempfile->directory) {
|
||||
if (in_signal_handler)
|
||||
rmdir(tempfile->directory);
|
||||
return rmdir(tempfile->directory);
|
||||
else
|
||||
rmdir_or_warn(tempfile->directory);
|
||||
return rmdir_or_warn(tempfile->directory);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void remove_tempfiles(int in_signal_handler)
|
||||
|
@ -353,16 +355,19 @@ int rename_tempfile(struct tempfile **tempfile_p, const char *path)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void delete_tempfile(struct tempfile **tempfile_p)
|
||||
int delete_tempfile(struct tempfile **tempfile_p)
|
||||
{
|
||||
struct tempfile *tempfile = *tempfile_p;
|
||||
int err = 0;
|
||||
|
||||
if (!is_tempfile_active(tempfile))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
close_tempfile_gently(tempfile);
|
||||
unlink_or_warn(tempfile->filename.buf);
|
||||
remove_template_directory(tempfile, 0);
|
||||
err |= close_tempfile_gently(tempfile);
|
||||
err |= unlink_or_warn(tempfile->filename.buf);
|
||||
err |= remove_template_directory(tempfile, 0);
|
||||
deactivate_tempfile(tempfile);
|
||||
*tempfile_p = NULL;
|
||||
|
||||
return err ? -1 : 0;
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ int reopen_tempfile(struct tempfile *tempfile);
|
|||
* `delete_tempfile()` for a `tempfile` object that has already been
|
||||
* deleted or renamed.
|
||||
*/
|
||||
void delete_tempfile(struct tempfile **tempfile_p);
|
||||
int delete_tempfile(struct tempfile **tempfile_p);
|
||||
|
||||
/*
|
||||
* Close the file descriptor and/or file pointer if they are still
|
||||
|
|
Loading…
Reference in a new issue