git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 2/2] treewide: use is_missing_file_error() where ENOENT and  ENOTDIR are checked
Date: Tue, 30 May 2017 09:32:54 +0900	[thread overview]
Message-ID: <xmqqa85vfakp.fsf_-_@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <xmqqefv7famk.fsf_-_@gitster.mtv.corp.google.com> (Junio C. Hamano's message of "Tue, 30 May 2017 09:31:47 +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                | 2 +-
 builtin/rm.c           | 2 +-
 builtin/update-index.c | 2 +-
 diff-lib.c             | 2 +-
 dir.c                  | 2 +-
 setup.c                | 2 +-
 sha1_name.c            | 4 ++--
 wrapper.c              | 4 ++--
 8 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/apply.c b/apply.c
index 0e2caeab9c..59bb3497de 100644
--- 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;
diff --git a/builtin/rm.c b/builtin/rm.c
index fb79dcab18..30c4332c68 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 d530e89368..4e9402984a 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -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));
 }
diff --git a/diff-lib.c b/diff-lib.c
index 52447466b5..88fc71e89e 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -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 aeeb5ce104..98efe9d1c5 100644
--- 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 8f64fbdfb2..bb6a2c1beb 100644
--- 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);
 }
diff --git a/sha1_name.c b/sha1_name.c
index 26ceec1d79..af7500037d 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -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);
 
diff --git a/wrapper.c b/wrapper.c
index 0542fc7582..2fbbd81359 100644
--- 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)
-- 
2.13.0-496-ga689fffbe2


  reply	other threads:[~2017-05-30  0:32 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-22  6:11 What's cooking in git.git (May 2017, #06; Mon, 22) Junio C Hamano
2017-05-22 17:42 ` Jonathan Nieder
2017-05-23  3:33   ` Junio C Hamano
2017-05-23  5:02     ` Jonathan Nieder
2017-05-23  5:14       ` Junio C Hamano
2017-05-25 12:58 ` Duy Nguyen
2017-05-26  2:56   ` Junio C Hamano
2017-05-26  3:34   ` [PATCH v3 00/13] reporting unexpected errors after (f)open Junio C Hamano
2017-05-26  3:34     ` [PATCH v3 01/13] git_fopen: fix a sparse 'not declared' warning Junio C Hamano
2017-05-26  3:34     ` [PATCH v3 02/13] use xfopen() in more places Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 03/13] clone: use xfopen() instead of fopen() Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 04/13] config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 05/13] config.mak.uname: set FREAD_READS_DIRECTORIES for Darwin, too Junio C Hamano
2017-05-30 18:51       ` Stefan Beller
2017-05-30 23:14         ` Junio C Hamano
2017-05-30 23:32           ` Stefan Beller
2017-05-26  3:35     ` [PATCH v3 06/13] wrapper.c: add and use warn_on_fopen_errors() Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 07/13] wrapper.c: add and use fopen_or_warn() Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 08/13] wrapper.c: make warn_on_inaccessible() static Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 09/13] print errno when reporting a system call error Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 10/13] rerere.c: move error_errno() closer to the source system call Junio C Hamano
2017-05-30 18:58       ` Stefan Beller
2017-05-26  3:35     ` [PATCH v3 11/13] log: fix memory leak in open_next_file() Junio C Hamano
2017-05-26  3:35     ` [PATCH v3 12/13] wrapper: factor out is_missing_file_error() Junio C Hamano
2017-05-30  0:31       ` [PATCH 1/2] compat-util: is_missing_file_error() Junio C Hamano
2017-05-30  0:32         ` Junio C Hamano [this message]
2017-05-26  3:35     ` [PATCH v3 13/13] is_missing_file_error(): work around EINVAL on Windows Junio C Hamano
2017-05-29 20:25       ` [PATCH 1/2] mingw: verify that paths are not mistaken for remote nicknames Johannes Sixt
2017-05-29 20:27         ` [PATCH 2/2] mingw_fopen: report ENOENT for invalid file names Johannes Sixt
2017-05-29 20:40         ` [PATCH 1/2] mingw: verify that paths are not mistaken for remote nicknames Ævar Arnfjörð Bjarmason
2017-05-29 21:02           ` Johannes Sixt
2017-05-29 21:59             ` Ramsay Jones
2017-05-30  0:03               ` Junio C Hamano
2017-05-30 13:40                 ` Ramsay Jones
2017-05-29 23:53             ` Junio C Hamano
2017-05-30  4:46             ` Junio C Hamano
2017-05-30 20:35               ` Johannes Sixt
2017-05-30  0:29         ` Junio C Hamano
2017-05-30 19:13       ` [PATCH v3 13/13] is_missing_file_error(): work around EINVAL on Windows Stefan Beller
2017-05-30 23:17         ` Junio C Hamano
2017-05-30 23:32           ` Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqa85vfakp.fsf_-_@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).