summaryrefslogtreecommitdiff
path: root/dir-iterator.c
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2019-07-10 23:58:58 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-07-11 20:52:15 (GMT)
commitc9bba372ed9ee0c5ea1a4037c3c723a6c31f5921 (patch)
treee054b1ffa6c5a508b65128724aee6e1457e1230c /dir-iterator.c
parent150791adbf1eb432af0b895d81eef5c2717aa6cc (diff)
downloadgit-c9bba372ed9ee0c5ea1a4037c3c723a6c31f5921.zip
git-c9bba372ed9ee0c5ea1a4037c3c723a6c31f5921.tar.gz
git-c9bba372ed9ee0c5ea1a4037c3c723a6c31f5921.tar.bz2
dir-iterator: use warning_errno when possible
Change warning(..., strerror(errno)) by warning_errno(...). This helps to unify warning display besides simplifying a bit the code. Also, improve warning messages by surrounding paths with quotation marks and using more meaningful statements. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir-iterator.c')
-rw-r--r--dir-iterator.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/dir-iterator.c b/dir-iterator.c
index f2dcd82..0c88808 100644
--- a/dir-iterator.c
+++ b/dir-iterator.c
@@ -71,8 +71,8 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
level->dir = opendir(iter->base.path.buf);
if (!level->dir && errno != ENOENT) {
- warning("error opening directory %s: %s",
- iter->base.path.buf, strerror(errno));
+ warning_errno("error opening directory '%s'",
+ iter->base.path.buf);
/* Popping the level is handled below */
}
@@ -122,11 +122,11 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
if (!de) {
/* This level is exhausted; pop up a level. */
if (errno) {
- warning("error reading directory %s: %s",
- iter->base.path.buf, strerror(errno));
+ warning_errno("error reading directory '%s'",
+ iter->base.path.buf);
} else if (closedir(level->dir))
- warning("error closing directory %s: %s",
- iter->base.path.buf, strerror(errno));
+ warning_errno("error closing directory '%s'",
+ iter->base.path.buf);
level->dir = NULL;
if (--iter->levels_nr == 0)
@@ -140,9 +140,8 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
strbuf_addstr(&iter->base.path, de->d_name);
if (lstat(iter->base.path.buf, &iter->base.st) < 0) {
if (errno != ENOENT)
- warning("error reading path '%s': %s",
- iter->base.path.buf,
- strerror(errno));
+ warning_errno("failed to stat '%s'",
+ iter->base.path.buf);
continue;
}
@@ -170,9 +169,11 @@ int dir_iterator_abort(struct dir_iterator *dir_iterator)
&iter->levels[iter->levels_nr - 1];
if (level->dir && closedir(level->dir)) {
+ int saved_errno = errno;
strbuf_setlen(&iter->base.path, level->prefix_len);
- warning("error closing directory %s: %s",
- iter->base.path.buf, strerror(errno));
+ errno = saved_errno;
+ warning_errno("error closing directory '%s'",
+ iter->base.path.buf);
}
}