* src/chmod.c: Revert last change. There is a better way.
authorJim Meyering <jim@meyering.net>
Wed, 20 Sep 2006 11:26:18 +0000 (11:26 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 20 Sep 2006 11:26:18 +0000 (11:26 +0000)
* src/chown-core.c: Likewise.

ChangeLog
src/chmod.c
src/chown-core.c

index db94093..75405e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-20  Jim Meyering  <jim@meyering.net>
+
+       * src/chmod.c: Revert last change.  There is a better way.
+       * src/chown-core.c: Likewise.
+
 2006-09-19  Paul Eggert  <eggert@cs.ucla.edu>
 
        * src/ln.c (target_directory_operand): Rewrite to avoid porting
index eb1cfe7..2961136 100644 (file)
@@ -85,10 +85,6 @@ static enum Verbosity verbosity = V_off;
    Otherwise NULL.  */
 static struct dev_ino *root_dev_ino;
 
-/* Error number associated with the working directory, or 0 if no
-   error has been found.  */
-static int wd_errno;
-
 /* For long options that have no equivalent short option, use a
    non-character as a pseudo short option, starting with CHAR_MAX + 1.  */
 enum
@@ -283,19 +279,16 @@ process_file (FTS *fts, FTSENT *ent)
   return ok;
 }
 
-/* Recursively change the modes of the command-line operand FILE.
-   BIT_FLAGS controls how fts works.
+/* Recursively change the modes of the specified FILES (the last entry
+   of which is NULL).  BIT_FLAGS controls how fts works.
    Return true if successful.  */
 
 static bool
-chmod_file (char *file, int bit_flags)
+process_files (char **files, int bit_flags)
 {
-  char *files[2];
   bool ok = true;
-  FTS *fts;
-  files[0] = file;
-  files[1] = NULL;
-  fts = xfts_open (files, bit_flags, NULL);
+
+  FTS *fts = xfts_open (files, bit_flags, NULL);
 
   while (1)
     {
@@ -316,31 +309,10 @@ chmod_file (char *file, int bit_flags)
       ok &= process_file (fts, ent);
     }
 
-  if (fts_close (fts) != 0)
-    wd_errno = errno;
-
-  return ok;
-}
-
-/* Recursively change the modes of the specified FILES (the last entry
-   of which is NULL).  BIT_FLAGS controls how fts works.
-   Return true if successful.  */
-static bool
-process_files (char **files, int bit_flags)
-{
-  bool ok = true;
-  wd_errno = 0;
-
-  for (; *files; files++)
-    {
-      if (! IS_ABSOLUTE_FILE_NAME (*files) && wd_errno)
-       {
-         error (0, wd_errno, ".");
-         ok = false;
-       }
-      else
-       ok &= chmod_file (*files, bit_flags);
-    }
+  /* Ignore failure, since the only way it can do so is in failing to
+     return to the original directory, and since we're about to exit,
+     that doesn't matter.  */
+  fts_close (fts);
 
   return ok;
 }
index b5b0f3b..39cb34d 100644 (file)
@@ -51,10 +51,6 @@ enum RCH_status
     RC_error
   };
 
-/* Error number associated with the working directory, or 0 if no
-   error has been found.  */
-static int wd_errno;
-
 extern void
 chopt_init (struct Chown_option *chopt)
 {
@@ -426,7 +422,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
   return ok;
 }
 
-/* Change the owner and/or group of the specified FILE.
+/* Change the owner and/or group of the specified FILES.
    BIT_FLAGS specifies how to treat each symlink-to-directory
    that is encountered during a recursive traversal.
    CHOPT specifies additional options.
@@ -435,11 +431,11 @@ change_file_owner (FTS *fts, FTSENT *ent,
    If REQUIRED_UID and/or REQUIRED_GID is not -1, then change only
    files with user ID and group ID that match the non-(-1) value(s).
    Return true if successful.  */
-static bool
-chown_file (char *file, int bit_flags,
-           uid_t uid, gid_t gid,
-           uid_t required_uid, gid_t required_gid,
-           struct Chown_option const *chopt)
+extern bool
+chown_files (char **files, int bit_flags,
+            uid_t uid, gid_t gid,
+            uid_t required_uid, gid_t required_gid,
+            struct Chown_option const *chopt)
 {
   bool ok = true;
 
@@ -449,11 +445,7 @@ chown_file (char *file, int bit_flags,
                    ? 0
                    : FTS_NOSTAT);
 
-  FTS *fts;
-  char *files[2];
-  files[0] = file;
-  files[1] = NULL;
-  fts = xfts_open (files, bit_flags | stat_flags, NULL);
+  FTS *fts = xfts_open (files, bit_flags | stat_flags, NULL);
 
   while (1)
     {
@@ -475,40 +467,10 @@ chown_file (char *file, int bit_flags,
                               required_uid, required_gid, chopt);
     }
 
-  if (fts_close (fts) != 0)
-    wd_errno = errno;
-
-  return ok;
-}
-
-/* Change the owner and/or group of the specified FILES.
-   BIT_FLAGS specifies how to treat each symlink-to-directory
-   that is encountered during a recursive traversal.
-   CHOPT specifies additional options.
-   If UID is not -1, then change the owner id of each file to UID.
-   If GID is not -1, then change the group id of each file to GID.
-   If REQUIRED_UID and/or REQUIRED_GID is not -1, then change only
-   files with user ID and group ID that match the non-(-1) value(s).
-   Return true if successful.  */
-extern bool
-chown_files (char **files, int bit_flags,
-            uid_t uid, gid_t gid,
-            uid_t required_uid, gid_t required_gid,
-            struct Chown_option const *chopt)
-{
-  bool ok = true;
-
-  for (; *files; files++)
-    {
-      if (! IS_ABSOLUTE_FILE_NAME (*files) && wd_errno)
-       {
-         error (0, wd_errno, ".");
-         ok = false;
-       }
-      else
-       ok &= chown_file (*files, bit_flags, uid, gid,
-                         required_uid, required_gid, chopt);
-    }
+  /* Ignore failure, since the only way it can do so is in failing to
+     return to the original directory, and since we're about to exit,
+     that doesn't matter.  */
+  fts_close (fts);
 
   return ok;
 }