path: root/sha1_name.c
diff options
authorJunio C Hamano <>2017-06-13 20:47:06 (GMT)
committerJunio C Hamano <>2017-06-13 20:47:07 (GMT)
commit93dd544f54ea596e9d70d06c100123c10689861c (patch)
tree78b1af433503d44eb977ed7e6464d4d959fb4809 /sha1_name.c
parent41dd4330a1210003bd702ec4a9301ed68e60864d (diff)
parentc7054209d65db430bdbcb2243288e63cea3e417c (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 'sha1_name.c')
1 files changed, 2 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c
index e9ffe68..5126853 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1408,7 +1408,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,
@@ -1473,7 +1473,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).",