treewide: use is_missing_file_error() where ENOENT and ENOTDIR are checked
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 00:23:33 +0000 (09:23 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 May 2017 00:29:00 +0000 (09:29 +0900)
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>
apply.c
builtin/rm.c
builtin/update-index.c
diff-lib.c
dir.c
setup.c
sha1_name.c
wrapper.c
diff --git a/apply.c b/apply.c
index 0e2caeab9cc523364e0cfbb8cbbb5aba1a0a58ee..59bb3497dea1ec74e90846b120277cdf5407e6fa 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3741,7 +3741,7 @@ static int check_to_create(struct apply_state *state,
                        return 0;
 
                return EXISTS_IN_WORKTREE;
-       } else if ((errno != ENOENT) && (errno != ENOTDIR)) {
+       } else if (!is_missing_file_error(errno)) {
                return error_errno("%s", new_name);
        }
        return 0;
index fb79dcab181558e79e3934363cac3c712ffbd3aa..30c4332c68e24032afa9df49a894d01310a08d68 100644 (file)
@@ -129,7 +129,7 @@ static int check_local_mod(struct object_id *head, int index_only)
                ce = active_cache[pos];
 
                if (lstat(ce->name, &st) < 0) {
-                       if (errno != ENOENT && errno != ENOTDIR)
+                       if (!is_missing_file_error(errno))
                                warning_errno(_("failed to stat '%s'"), ce->name);
                        /* It already vanished from the working tree */
                        continue;
index d530e89368b42bf1465784b80163b9158a06585a..4e9402984aff394adf9b0853343e5f906fca238c 100644 (file)
@@ -253,7 +253,7 @@ static int remove_one_path(const char *path)
  */
 static int process_lstat_error(const char *path, int err)
 {
-       if (err == ENOENT || err == ENOTDIR)
+       if (is_missing_file_error(err))
                return remove_one_path(path);
        return error("lstat(\"%s\"): %s", path, strerror(err));
 }
index 52447466b5d16c4e8978795b0122e2182e83c5cb..88fc71e89e191ae2defcb2ca74e87765126a45d7 100644 (file)
@@ -29,7 +29,7 @@
 static int check_removed(const struct cache_entry *ce, struct stat *st)
 {
        if (lstat(ce->name, st) < 0) {
-               if (errno != ENOENT && errno != ENOTDIR)
+               if (!is_missing_file_error(errno))
                        return -1;
                return 1;
        }
diff --git a/dir.c b/dir.c
index aeeb5ce10490ef1e0adb907d1e21bcbbbbb401ac..98efe9d1c5d706bdaf12da508783006a4c882864 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -2235,7 +2235,7 @@ int remove_path(const char *name)
 {
        char *slash;
 
-       if (unlink(name) && errno != ENOENT && errno != ENOTDIR)
+       if (unlink(name) && !is_missing_file_error(errno))
                return -1;
 
        slash = strrchr(name, '/');
diff --git a/setup.c b/setup.c
index 8f64fbdfb28fc2e487cfdba76561e5b3a25766f0..bb6a2c1bebf8081f62f65fcbc221e20e5fa4aa93 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -147,7 +147,7 @@ int check_filename(const char *prefix, const char *arg)
                name = arg;
        if (!lstat(name, &st))
                return 1; /* file exists */
-       if (errno == ENOENT || errno == ENOTDIR)
+       if (is_missing_file_error(errno))
                return 0; /* file does not exist */
        die_errno("failed to stat '%s'", arg);
 }
index 26ceec1d799afad6c6831cba00ca4d0ffab7979f..af7500037d743ab818906ab179fd6e37729afeba 100644 (file)
@@ -1406,7 +1406,7 @@ static void diagnose_invalid_sha1_path(const char *prefix,
        if (file_exists(filename))
                die("Path '%s' exists on disk, but not in '%.*s'.",
                    filename, object_name_len, object_name);
-       if (errno == ENOENT || errno == ENOTDIR) {
+       if (is_missing_file_error(errno)) {
                char *fullname = xstrfmt("%s%s", prefix, filename);
 
                if (!get_tree_entry(tree_sha1, fullname,
@@ -1471,7 +1471,7 @@ static void diagnose_invalid_index_path(int stage,
 
        if (file_exists(filename))
                die("Path '%s' exists on disk, but not in the index.", filename);
-       if (errno == ENOENT || errno == ENOTDIR)
+       if (is_missing_file_error(errno))
                die("Path '%s' does not exist (neither on disk nor in the index).",
                    filename);
 
index 0542fc75821fdbdd7bfecebec5f7df01e49dcb0c..2fbbd813590a36c90bc1cc7177373752b6eae981 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -583,8 +583,8 @@ void warn_on_inaccessible(const char *path)
 
 static int access_error_is_ok(int err, unsigned flag)
 {
-       return err == ENOENT || err == ENOTDIR ||
-               ((flag & ACCESS_EACCES_OK) && err == EACCES);
+       return (is_missing_file_error(err) ||
+               ((flag & ACCESS_EACCES_OK) && err == EACCES));
 }
 
 int access_or_warn(const char *path, int mode, unsigned flag)