bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

coreutils isdir cleanup / removal


From: Paul Eggert
Subject: coreutils isdir cleanup / removal
Date: Mon, 02 Aug 2004 13:20:42 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Coreutils "install" uses an isdir function to test whether a named file
is a directory.  It returns int and probably should return bool,
however, when cleaning this up I noticed that all the invocations of
isdir were unnecessary.  So I installed this patch.

2004-08-02  Paul Eggert  <address@hidden>

        * lib/isdir.c: Remove; no longer needed.
        * lib/Makefile.am (libfetish_a_SOURCES): Remove isdir.c.
        * src/install.c (isdir): Remove decl.
        (install_file_to_path): Rely on make_path to fail if the destination
        is not a directory, by passing preserve_existing==true to it.
        Hence we no longer need to call isdir.
        Free dest_dir immediately when it's no longer needed, rather than
        waiting until the end of the function.
        (copy_file): Don't bother calling isdir, as copy will do the
        right thing if the destination is a directory.

Index: lib/Makefile.am
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/Makefile.am,v
retrieving revision 1.191
diff -p -u -r1.191 Makefile.am
--- lib/Makefile.am     27 Jul 2004 23:11:55 -0000      1.191
+++ lib/Makefile.am     2 Aug 2004 20:07:15 -0000
@@ -73,7 +73,6 @@ libfetish_a_SOURCES = \
   hard-locale.c hard-locale.h \
   human.c human.h \
   idcache.c \
-  isdir.c \
   imaxtostr.c \
   lchown.h \
   linebuffer.c linebuffer.h \
Index: src/install.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/install.c,v
retrieving revision 1.164
diff -p -u -r1.164 install.c
--- src/install.c       30 Jul 2004 07:57:50 -0000      1.164
+++ src/install.c       2 Aug 2004 20:06:43 -0000
@@ -72,8 +72,6 @@ gid_t getgid ();
 /* Number of bytes of a file to copy at a time. */
 #define READ_SIZE (32 * 1024)
 
-bool isdir (char const *);
-
 int stat ();
 
 static bool change_timestamps (const char *from, const char *to);
@@ -414,29 +412,26 @@ static bool
 install_file_to_path (const char *from, const char *to,
                      const struct cp_options *x)
 {
-  char *dest_dir;
+  char *dest_dir = dir_name (to);
   bool ok = true;
 
-  dest_dir = dir_name (to);
-
-  /* check to make sure this is a path (not install a b ) */
-  if (!STREQ (dest_dir, ".")
-      && !isdir (dest_dir))
+  /* Make sure that the parent of the destination is a directory.  */
+  if (! STREQ (dest_dir, "."))
     {
       /* Someone will probably ask for a new option or three to specify
         owner, group, and permissions for parent directories.  Remember
         that this option is intended mainly to help installers when the
         distribution doesn't provide proper install rules.  */
 #define DIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
-      ok = make_path (dest_dir, DIR_MODE, DIR_MODE, owner_id, group_id, false,
+      ok = make_path (dest_dir, DIR_MODE, DIR_MODE, owner_id, group_id, true,
                      (x->verbose ? _("creating directory %s") : NULL));
     }
 
+  free (dest_dir);
+
   if (ok)
     ok = install_file_in_file (from, to, x);
 
-  free (dest_dir);
-
   return ok;
 }
 
@@ -484,12 +479,9 @@ copy_file (const char *from, const char 
 
   /* Allow installing from non-regular files like /dev/null.
      Charles Karney reported that some Sun version of install allows that
-     and that sendmail's installation process relies on the behavior.  */
-  if (isdir (from))
-    {
-      error (0, 0, _("%s is a directory"), quote (from));
-      return false;
-    }
+     and that sendmail's installation process relies on the behavior.
+     However, since !x->recursive, the call to "copy" will fail if FROM
+     is a directory.  */
 
   return copy (from, to, false, x, &copy_into_self, NULL);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]