Skip to content

Commit c705420

Browse files
committed
treewide: use is_missing_file_error() where ENOENT and ENOTDIR are checked
Using the is_missing_file_error() helper introduced in the previous step, update all hits from $ git grep -e ENOENT --and -e ENOTDIR There are codepaths that only check ENOENT, and it is possible that some of them should be checking both. Updating them is kept out of this step deliberately, as we do not want to change behaviour in this step. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent dc5a18b commit c705420

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3741,7 +3741,7 @@ static int check_to_create(struct apply_state *state,
37413741
return 0;
37423742

37433743
return EXISTS_IN_WORKTREE;
3744-
} else if ((errno != ENOENT) && (errno != ENOTDIR)) {
3744+
} else if (!is_missing_file_error(errno)) {
37453745
return error_errno("%s", new_name);
37463746
}
37473747
return 0;

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static int check_local_mod(struct object_id *head, int index_only)
129129
ce = active_cache[pos];
130130

131131
if (lstat(ce->name, &st) < 0) {
132-
if (errno != ENOENT && errno != ENOTDIR)
132+
if (!is_missing_file_error(errno))
133133
warning_errno(_("failed to stat '%s'"), ce->name);
134134
/* It already vanished from the working tree */
135135
continue;

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static int remove_one_path(const char *path)
253253
*/
254254
static int process_lstat_error(const char *path, int err)
255255
{
256-
if (err == ENOENT || err == ENOTDIR)
256+
if (is_missing_file_error(err))
257257
return remove_one_path(path);
258258
return error("lstat(\"%s\"): %s", path, strerror(err));
259259
}

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
static int check_removed(const struct cache_entry *ce, struct stat *st)
3030
{
3131
if (lstat(ce->name, st) < 0) {
32-
if (errno != ENOENT && errno != ENOTDIR)
32+
if (!is_missing_file_error(errno))
3333
return -1;
3434
return 1;
3535
}

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ int remove_path(const char *name)
22352235
{
22362236
char *slash;
22372237

2238-
if (unlink(name) && errno != ENOENT && errno != ENOTDIR)
2238+
if (unlink(name) && !is_missing_file_error(errno))
22392239
return -1;
22402240

22412241
slash = strrchr(name, '/');

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg)
147147
name = arg;
148148
if (!lstat(name, &st))
149149
return 1; /* file exists */
150-
if (errno == ENOENT || errno == ENOTDIR)
150+
if (is_missing_file_error(errno))
151151
return 0; /* file does not exist */
152152
die_errno("failed to stat '%s'", arg);
153153
}

sha1_name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ static void diagnose_invalid_sha1_path(const char *prefix,
14061406
if (file_exists(filename))
14071407
die("Path '%s' exists on disk, but not in '%.*s'.",
14081408
filename, object_name_len, object_name);
1409-
if (errno == ENOENT || errno == ENOTDIR) {
1409+
if (is_missing_file_error(errno)) {
14101410
char *fullname = xstrfmt("%s%s", prefix, filename);
14111411

14121412
if (!get_tree_entry(tree_sha1, fullname,
@@ -1471,7 +1471,7 @@ static void diagnose_invalid_index_path(int stage,
14711471

14721472
if (file_exists(filename))
14731473
die("Path '%s' exists on disk, but not in the index.", filename);
1474-
if (errno == ENOENT || errno == ENOTDIR)
1474+
if (is_missing_file_error(errno))
14751475
die("Path '%s' does not exist (neither on disk nor in the index).",
14761476
filename);
14771477

wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ void warn_on_inaccessible(const char *path)
583583

584584
static int access_error_is_ok(int err, unsigned flag)
585585
{
586-
return err == ENOENT || err == ENOTDIR ||
587-
((flag & ACCESS_EACCES_OK) && err == EACCES);
586+
return (is_missing_file_error(err) ||
587+
((flag & ACCESS_EACCES_OK) && err == EACCES));
588588
}
589589

590590
int access_or_warn(const char *path, int mode, unsigned flag)

0 commit comments

Comments
 (0)