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>

Matheus Tavares committed Jul 10, 2019 at 20:58 UTC c9bba372ed9ee0c5ea1a4037c3c723a6c31f5921
1 file changed +12 -11
dir-iterator.c
+12 -11
@@ -71,8 +71,8 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
71
72 level->dir = opendir(iter->base.path.buf);
73 if (!level->dir && errno != ENOENT) {
74 - warning("error opening directory %s: %s",
75 - iter->base.path.buf, strerror(errno));
74 + warning_errno("error opening directory '%s'",
75 + iter->base.path.buf);
76 /* Popping the level is handled below */
77 }
78
@@ -122,11 +122,11 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
122 if (!de) {
123 /* This level is exhausted; pop up a level. */
124 if (errno) {
125 - warning("error reading directory %s: %s",
126 - iter->base.path.buf, strerror(errno));
125 + warning_errno("error reading directory '%s'",
126 + iter->base.path.buf);
127 } else if (closedir(level->dir))
128 - warning("error closing directory %s: %s",
129 - iter->base.path.buf, strerror(errno));
128 + warning_errno("error closing directory '%s'",
129 + iter->base.path.buf);
130
131 level->dir = NULL;
132 if (--iter->levels_nr == 0)
@@ -140,9 +140,8 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
140 strbuf_addstr(&iter->base.path, de->d_name);
141 if (lstat(iter->base.path.buf, &iter->base.st) < 0) {
142 if (errno != ENOENT)
143 - warning("error reading path '%s': %s",
144 - iter->base.path.buf,
145 - strerror(errno));
143 + warning_errno("failed to stat '%s'",
144 + iter->base.path.buf);
145 continue;
146 }
147
@@ -170,9 +169,11 @@ int dir_iterator_abort(struct dir_iterator *dir_iterator)
169 &iter->levels[iter->levels_nr - 1];
170
171 if (level->dir && closedir(level->dir)) {
172 + int saved_errno = errno;
173 strbuf_setlen(&iter->base.path, level->prefix_len);
174 - warning("error closing directory %s: %s",
175 - iter->base.path.buf, strerror(errno));
174 + errno = saved_errno;
175 + warning_errno("error closing directory '%s'",
176 + iter->base.path.buf);
177 }
178 }
179