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>
Junio C Hamano committed
May 30, 2017 at 09:23 UTC
c7054209d65db430bdbcb2243288e63cea3e417c
8 files changed
+10
-10
apply.c
+1
-1
@@ -3741,7 +3741,7 @@ static int check_to_create(struct apply_state *state,
3741
return 0;
3742
3743
return EXISTS_IN_WORKTREE;
3744
- } else if ((errno != ENOENT) && (errno != ENOTDIR)) {
3744
+ } else if (!is_missing_file_error(errno)) {
3745
return error_errno("%s", new_name);
3746
}
3747
return 0;
builtin/rm.c
+1
-1
@@ -129,7 +129,7 @@ static int check_local_mod(struct object_id *head, int index_only)
129
ce = active_cache[pos];
130
131
if (lstat(ce->name, &st) < 0) {
132
- if (errno != ENOENT && errno != ENOTDIR)
132
+ if (!is_missing_file_error(errno))
133
warning_errno(_("failed to stat '%s'"), ce->name);
134
/* It already vanished from the working tree */
135
continue;
builtin/update-index.c
+1
-1
@@ -253,7 +253,7 @@ static int remove_one_path(const char *path)
253
*/
254
static int process_lstat_error(const char *path, int err)
255
{
256
- if (err == ENOENT || err == ENOTDIR)
256
+ if (is_missing_file_error(err))
257
return remove_one_path(path);
258
return error("lstat(\"%s\"): %s", path, strerror(err));
259
}
diff-lib.c
+1
-1
@@ -29,7 +29,7 @@
29
static int check_removed(const struct cache_entry *ce, struct stat *st)
30
{
31
if (lstat(ce->name, st) < 0) {
32
- if (errno != ENOENT && errno != ENOTDIR)
32
+ if (!is_missing_file_error(errno))
33
return -1;
34
return 1;
35
}
dir.c
+1
-1
@@ -2235,7 +2235,7 @@ int remove_path(const char *name)
2235
{
2236
char *slash;
2237
2238
- if (unlink(name) && errno != ENOENT && errno != ENOTDIR)
2238
+ if (unlink(name) && !is_missing_file_error(errno))
2239
return -1;
2240
2241
slash = strrchr(name, '/');
setup.c
+1
-1
@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg)
147
name = arg;
148
if (!lstat(name, &st))
149
return 1; /* file exists */
150
- if (errno == ENOENT || errno == ENOTDIR)
150
+ if (is_missing_file_error(errno))
151
return 0; /* file does not exist */
152
die_errno("failed to stat '%s'", arg);
153
}
sha1_name.c
+2
-2
@@ -1406,7 +1406,7 @@ static void diagnose_invalid_sha1_path(const char *prefix,
1406
if (file_exists(filename))
1407
die("Path '%s' exists on disk, but not in '%.*s'.",
1408
filename, object_name_len, object_name);
1409
- if (errno == ENOENT || errno == ENOTDIR) {
1409
+ if (is_missing_file_error(errno)) {
1410
char *fullname = xstrfmt("%s%s", prefix, filename);
1411
1412
if (!get_tree_entry(tree_sha1, fullname,
@@ -1471,7 +1471,7 @@ static void diagnose_invalid_index_path(int stage,
1471
1472
if (file_exists(filename))
1473
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))
1475
die("Path '%s' does not exist (neither on disk nor in the index).",
1476
filename);
1477
wrapper.c
+2
-2
@@ -583,8 +583,8 @@ void warn_on_inaccessible(const char *path)
583
584
static int access_error_is_ok(int err, unsigned flag)
585
{
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));
588
}
589
590
int access_or_warn(const char *path, int mode, unsigned flag)