Skip to content

Commit c9bba37

Browse files
matheustavaresgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 150791a commit c9bba37

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

dir-iterator.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
7171

7272
level->dir = opendir(iter->base.path.buf);
7373
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);
7676
/* Popping the level is handled below */
7777
}
7878

@@ -122,11 +122,11 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
122122
if (!de) {
123123
/* This level is exhausted; pop up a level. */
124124
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);
127127
} 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);
130130

131131
level->dir = NULL;
132132
if (--iter->levels_nr == 0)
@@ -140,9 +140,8 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
140140
strbuf_addstr(&iter->base.path, de->d_name);
141141
if (lstat(iter->base.path.buf, &iter->base.st) < 0) {
142142
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);
146145
continue;
147146
}
148147

@@ -170,9 +169,11 @@ int dir_iterator_abort(struct dir_iterator *dir_iterator)
170169
&iter->levels[iter->levels_nr - 1];
171170

172171
if (level->dir && closedir(level->dir)) {
172+
int saved_errno = errno;
173173
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);
176177
}
177178
}
178179

0 commit comments

Comments
 (0)