Skip to content

Commit 691f1a2

Browse files
raalkmlgitster
authored andcommitted
replace direct calls to unlink(2) with unlink_or_warn
This helps to notice when something's going wrong, especially on systems which lock open files. I used the following criteria when selecting the code for replacement: - it was already printing a warning for the unlink failures - it is in a function which already printing something or is called from such a function - it is in a static function, returning void and the function is only called from a builtin main function (cmd_) - it is in a function which handles emergency exit (signal handlers) - it is in a function which is obvously cleaning up the lockfiles Signed-off-by: Alex Riesen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc71db3 commit 691f1a2

23 files changed

+44
-49
lines changed

builtin-apply.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,7 @@ static void remove_file(struct patch *patch, int rmdir_empty)
27812781
if (rmdir(patch->old_name))
27822782
warning("unable to remove submodule %s",
27832783
patch->old_name);
2784-
} else if (!unlink(patch->old_name) && rmdir_empty) {
2784+
} else if (!unlink_or_warn(patch->old_name) && rmdir_empty) {
27852785
remove_path(patch->old_name);
27862786
}
27872787
}
@@ -2891,7 +2891,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned
28912891
if (!try_create_file(newpath, mode, buf, size)) {
28922892
if (!rename(newpath, path))
28932893
return;
2894-
unlink(newpath);
2894+
unlink_or_warn(newpath);
28952895
break;
28962896
}
28972897
if (errno != EEXIST)

builtin-fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
814814
fd = hold_lock_file_for_update(&lock, shallow,
815815
LOCK_DIE_ON_ERROR);
816816
if (!write_shallow_commits(fd, 0)) {
817-
unlink(shallow);
817+
unlink_or_warn(shallow);
818818
rollback_lock_file(&lock);
819819
} else {
820820
commit_lock_file(&lock);

builtin-prune-packed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts)
2828
memcpy(pathname + len, de->d_name, 38);
2929
if (opts & DRY_RUN)
3030
printf("rm -f %s\n", pathname);
31-
else if (unlink(pathname) < 0)
32-
error("unable to unlink %s", pathname);
31+
else
32+
unlink_or_warn(pathname);
3333
display_progress(progress, i + 1);
3434
}
3535
pathname[len] = 0;

builtin-prune.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int prune_tmp_object(const char *path, const char *filename)
2727
}
2828
printf("Removing stale temporary file %s\n", fullpath);
2929
if (!show_only)
30-
unlink(fullpath);
30+
unlink_or_warn(fullpath);
3131
return 0;
3232
}
3333

@@ -47,7 +47,7 @@ static int prune_object(char *path, const char *filename, const unsigned char *s
4747
(type > 0) ? typename(type) : "unknown");
4848
}
4949
if (!show_only)
50-
unlink(fullpath);
50+
unlink_or_warn(fullpath);
5151
return 0;
5252
}
5353

builtin-receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
702702
unpack_status = unpack();
703703
execute_commands(unpack_status);
704704
if (pack_lockfile)
705-
unlink(pack_lockfile);
705+
unlink_or_warn(pack_lockfile);
706706
if (report_status)
707707
report(unpack_status);
708708
run_receive_hook(post_receive_hook);

builtin-remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ static int migrate_file(struct remote *remote)
525525
path = git_path("remotes/%s", remote->name);
526526
else if (remote->origin == REMOTE_BRANCHES)
527527
path = git_path("branches/%s", remote->name);
528-
if (path && unlink(path))
529-
warning("failed to remove '%s'", path);
528+
if (path)
529+
unlink_or_warn(path);
530530
return 0;
531531
}
532532

builtin-rerere.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
116116
if (!has_rerere_resolution(name))
117117
unlink_rr_item(name);
118118
}
119-
unlink(git_path("rr-cache/MERGE_RR"));
119+
unlink_or_warn(git_path("rr-cache/MERGE_RR"));
120120
} else if (!strcmp(argv[1], "gc"))
121121
garbage_collect(&merge_rr);
122122
else if (!strcmp(argv[1], "status"))

builtin-tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static void create_tag(const unsigned char *object, const char *tag,
338338
exit(128);
339339
}
340340
if (path) {
341-
unlink(path);
341+
unlink_or_warn(path);
342342
free(path);
343343
}
344344
}

builtin-verify-tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
5555
close(gpg.in);
5656
ret = finish_command(&gpg);
5757

58-
unlink(path);
58+
unlink_or_warn(path);
5959

6060
return ret;
6161
}

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void remove_tempfile(void)
189189
int i;
190190
for (i = 0; i < ARRAY_SIZE(diff_temp); i++) {
191191
if (diff_temp[i].name == diff_temp[i].tmp_path)
192-
unlink(diff_temp[i].name);
192+
unlink_or_warn(diff_temp[i].name);
193193
diff_temp[i].name = NULL;
194194
}
195195
}

0 commit comments

Comments
 (0)