]> Savannah Git Hosting - gnulib.git/commitdiff
fts: be consistent about AT_NO_AUTOMOUNT
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 Mar 2022 19:54:13 +0000 (11:54 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 9 Mar 2022 19:55:39 +0000 (11:55 -0800)
* lib/fts.c (fts_stat): Use fstatat with AT_NO_AUTOMOUNT
consistently, instead of sometimes using stat (which implies
AT_NO_AUTOMOUNT) and sometimes using fstatat without AT_NO_AUTOMOUNT.
Remove a goto while we’re at it.

ChangeLog
lib/fts.c

index e3f0ed216c890fd81d48a35a21e0606aaf7d4ffd..58873a176271a919dcb52353ef29f3b28626ee35 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-03-09  Paul Eggert  <eggert@cs.ucla.edu>
+
+       fts: be consistent about AT_NO_AUTOMOUNT
+       * lib/fts.c (fts_stat): Use fstatat with AT_NO_AUTOMOUNT
+       consistently, instead of sometimes using stat (which implies
+       AT_NO_AUTOMOUNT) and sometimes using fstatat without AT_NO_AUTOMOUNT.
+       Remove a goto while we’re at it.
+
 2022-03-07  Pádraig Brady  <P@draigBrady.com>
 
        fcntl-h: add AT_NO_AUTOMOUNT
index 706c56c597c4f0f0e442eebe33497e1bf3a9f8d7..a1a7c09fdb1acb3c6a286c6dd4aff45e4304558d 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -1766,7 +1766,8 @@ fts_stat(FTS *sp, register FTSENT *p, bool follow)
 {
         struct stat *sbp = p->fts_statp;
 
-        if (p->fts_level == FTS_ROOTLEVEL && ISSET(FTS_COMFOLLOW))
+        if (ISSET (FTS_LOGICAL)
+            || (ISSET (FTS_COMFOLLOW) && p->fts_level == FTS_ROOTLEVEL))
                 follow = true;
 
         /*
@@ -1774,22 +1775,21 @@ fts_stat(FTS *sp, register FTSENT *p, bool follow)
          * a stat(2).  If that fails, check for a non-existent symlink.  If
          * fail, set the errno from the stat call.
          */
-        if (ISSET(FTS_LOGICAL) || follow) {
-                if (stat(p->fts_accpath, sbp)) {
-                        if (errno == ENOENT
-                            && lstat(p->fts_accpath, sbp) == 0) {
-                                __set_errno (0);
-                                return (FTS_SLNONE);
-                        }
-                        p->fts_errno = errno;
-                        goto err;
-                }
-        } else if (fstatat(sp->fts_cwd_fd, p->fts_accpath, sbp,
-                           AT_SYMLINK_NOFOLLOW)) {
-                p->fts_errno = errno;
-err:            memset(sbp, 0, sizeof(struct stat));
-                return (FTS_NS);
-        }
+        int flags = (follow ? 0 : AT_SYMLINK_NOFOLLOW) | AT_NO_AUTOMOUNT;
+        if (fstatat (sp->fts_cwd_fd, p->fts_accpath, sbp, flags) < 0)
+          {
+            if (follow && errno == ENOENT
+                && 0 <= fstatat (sp->fts_cwd_fd, p->fts_accpath, sbp,
+                                 AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT))
+              {
+                __set_errno (0);
+                return FTS_SLNONE;
+              }
+
+            p->fts_errno = errno;
+            memset (sbp, 0, sizeof *sbp);
+            return FTS_NS;
+          }
 
         if (S_ISDIR(sbp->st_mode)) {
                 if (ISDOT(p->fts_name)) {