diff options
author | Jim Meyering <jim@meyering.net> | 2003-02-05 15:08:15 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-02-05 15:08:15 +0000 |
commit | 6e6188765a24b2380f2a9cc709c7fccdfd294015 (patch) | |
tree | cdb0d0b18cbb801598751a1b80b7150ab4d47dc8 /lib | |
parent | 862ae182e136045fe081384a88d6a9e9db78e201 (diff) | |
download | coreutils-6e6188765a24b2380f2a9cc709c7fccdfd294015.tar.xz |
(process_entry): When using FTW_DEPTH, call `func',
the user-supplied callback, once before any of its entries,
in case that part of the hierarchy should be pruned. `func'
does that by setting `data->skip'.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ftw.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -406,11 +406,20 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name, /* Remember the object. */ && (result = add_object (data, &st)) == 0)) { - result = ftw_dir (data, &st); + /* When processing a directory as part of a depth-first traversal, + invoke the users callback function with type=FTW_DPRE + just before processing any entry in that directory. + And if the callback sets ftw.skip, then don't process + any entries of the directory. */ + if ((data->flags & FTW_DEPTH) + && (result = (*data->func) (data->dirbuf, &st, FTW_DPRE, + &data->ftw)) == 0 + && ! data->ftw.skip) + result = ftw_dir (data, &st); if (result == 0 && (data->flags & FTW_CHDIR)) { - /* Change back to current directory. */ + /* Change back to parent directory. */ int done = 0; if (dir->stream != NULL) if (__fchdir (dirfd (dir->stream)) == 0) |