diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-06-13 23:47:06 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-13 23:47:07 +0300 |
commit | 93dd544f54ea596e9d70d06c100123c10689861c (patch) | |
tree | 78b1af433503d44eb977ed7e6464d4d959fb4809 /builtin | |
parent | 41dd4330a1210003bd702ec4a9301ed68e60864d (diff) | |
parent | c7054209d65db430bdbcb2243288e63cea3e417c (diff) |
Merge branch 'jc/noent-notdir'
Our code often opens a path to an optional file, to work on its
contents when we can successfully open it. We can ignore a failure
to open if such an optional file does not exist, but we do want to
report a failure in opening for other reasons (e.g. we got an I/O
error, or the file is there, but we lack the permission to open).
The exact errors we need to ignore are ENOENT (obviously) and
ENOTDIR (less obvious). Instead of repeating comparison of errno
with these two constants, introduce a helper function to do so.
* jc/noent-notdir:
treewide: use is_missing_file_error() where ENOENT and ENOTDIR are checked
compat-util: is_missing_file_error()
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/rm.c | 2 | ||||
-rw-r--r-- | builtin/update-index.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/builtin/rm.c b/builtin/rm.c index 7c323d0123..b39f10fcb6 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -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; diff --git a/builtin/update-index.c b/builtin/update-index.c index ebfc09faa0..f99b1e5790 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -257,7 +257,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)); } |