]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(process_entry): When using FTW_DEPTH, call `func',
authorJim Meyering <jim@meyering.net>
Wed, 5 Feb 2003 15:08:15 +0000 (15:08 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 5 Feb 2003 15:08:15 +0000 (15:08 +0000)
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'.

lib/ftw.c

index 8f2c2a81a4afa05e46e4788af5a9f944d6d6fdaf..3928cdaf9d052fd585349e456b8c1792e5c03a19 100644 (file)
--- a/lib/ftw.c
+++ b/lib/ftw.c
@@ -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)