diff options
author | John Ata <john.ata@baesystems.com> | 2016-10-17 14:47:02 -0400 |
---|---|---|
committer | Waldemar Brodkorb <wbx@uclibc-ng.org> | 2016-10-20 21:46:25 +0200 |
commit | a6cdfdfff38584cadec40b6d6f2df2651e0b34b8 (patch) | |
tree | 07a4e05bea8cbdb8b1d721976c047b320d58bf52 | |
parent | 545beca17885560298580b51619979529a309360 (diff) |
Fix nftw when called with FTW_CHDIR and FTW_DEPTH
Change directory back to the parent before processing
the directory (after the contents have already been processed).
Signed-off-by: John Ata <john.ata@baesystems.com>
-rw-r--r-- | libc/misc/ftw/ftw.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/libc/misc/ftw/ftw.c b/libc/misc/ftw/ftw.c index 05ea0fa66..c6241ed90 100644 --- a/libc/misc/ftw/ftw.c +++ b/libc/misc/ftw/ftw.c @@ -558,19 +558,14 @@ fail: --data->ftw.level; data->ftw.base = previous_base; - /* Finally, if we process depth-first report the directory. */ - if (result == 0 && (data->flags & FTW_DEPTH)) - result = (*data->func) (data->dirbuf, st, FTW_DP, &data->ftw); - - if (old_dir - && (data->flags & FTW_CHDIR) + if ((data->flags & FTW_CHDIR) && (result == 0 || ((data->flags & FTW_ACTIONRETVAL) && (result != -1 && result != FTW_STOP)))) { /* Change back to the parent directory. */ int done = 0; - if (old_dir->stream != NULL) + if (old_dir && old_dir->stream != NULL) if (__fchdir (dirfd (old_dir->stream)) == 0) done = 1; @@ -587,6 +582,10 @@ fail: } } + /* Finally, if we process depth-first report the directory. */ + if (result == 0 && (data->flags & FTW_DEPTH)) + result = (*data->func) (data->dirbuf, st, FTW_DP, &data->ftw); + return result; } |