summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-08-26 04:38:30 +0000
committerJim Meyering <jim@meyering.net>1993-08-26 04:38:30 +0000
commit429043125e1842b92f1cdbc6c0a2772316c9d34e (patch)
treea63cf2e0550e8c034c83e0703eab1dd82ffb9184
parent410da16d0250bcf31c51a160de9eccb92667c7fe (diff)
downloadcoreutils-429043125e1842b92f1cdbc6c0a2772316c9d34e.tar.xz
merge with 3.8.2
-rw-r--r--lib/Makefile.in3
-rw-r--r--lib/fnmatch.c2
-rw-r--r--lib/fsusage.c4
-rw-r--r--old/fileutils/ChangeLog27
-rw-r--r--old/fileutils/NEWS5
-rw-r--r--src/cp.c45
-rw-r--r--src/ls.c2
-rw-r--r--src/mv.c17
-rw-r--r--src/rm.c14
9 files changed, 93 insertions, 26 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 834f23fde..3a71cac2b 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -108,5 +108,6 @@ modechange.o: modechange.h
mountlist.o: mountlist.h
xgetcwd.o: pathmax.h
-# Prevent GNU make v3 from overflowing arg limit on SysV.
+# Tell versions [3.59,3.63) of GNU make not to export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 8a25a905d..2fb65b521 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -16,7 +16,7 @@ not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <errno.h>
diff --git a/lib/fsusage.c b/lib/fsusage.c
index c9ed26c87..9307a40b5 100644
--- a/lib/fsusage.c
+++ b/lib/fsusage.c
@@ -58,7 +58,7 @@ int statvfs ();
#endif
/* Return the number of TOSIZE-byte blocks used by
- BLOCKS FROMSIZE-byte blocks, rounding up. */
+ BLOCKS FROMSIZE-byte blocks, rounding away from zero. */
static long
adjust_blocks (blocks, fromsize, tosize)
@@ -70,7 +70,7 @@ adjust_blocks (blocks, fromsize, tosize)
else if (fromsize > tosize) /* E.g., from 2048 to 512. */
return blocks * (fromsize / tosize);
else /* E.g., from 256 to 512. */
- return (blocks + 1) / (tosize / fromsize);
+ return (blocks + (blocks < 0 ? -1 : +1)) / (tosize / fromsize);
}
/* Fill in the fields of FSP with information about space usage for
diff --git a/old/fileutils/ChangeLog b/old/fileutils/ChangeLog
index 5583c9b2c..b74560f97 100644
--- a/old/fileutils/ChangeLog
+++ b/old/fileutils/ChangeLog
@@ -1,9 +1,36 @@
+Wed Aug 25 21:40:00 EDT 1993
+
+ * cp.c: Add --parents as synonym for --path. Change --path to
+ --parents in comments. --path is deprecated.
+
+ * rm.c (clear_directory): Fix incorrect test for determining when
+ to reallocate buffer. Thanks to Ric Anderson <ric@CS.Arizona.EDU>.
+
+Fri Aug 13 17:19:52 1993 Jim Meyering (meyering@comco.com)
+
+ * fsusage (adjust_blocks): Round away from zero -- this matters
+ when computing the negative free-block count for disks that are
+ more than 100% full.
+
+ * mv.c (movefile): Use nested calls to stpcpy instead of sprintf.
+ (is_real_dir): New function.
+ (movefile): In addition to when dest is a directory, if dest has
+ a trailing `/' and source is not a directory, presume the target
+ is dest/`basename source`. This converts `mv a b/' to `mv a b/a'
+ when a is not a directory -- so the command will fail when a is a
+ non-directory and (b doesn't exist or b isn't a directory or a
+ symlink to a directory).
+
+ * ls.c (do_copy): Similarly, convert `cp a b/' to cp a b/a when
+ a is not a directory.
+
Wed Aug 4 17:43:18 1993 Jim Meyering (meyering@comco.com)
* ls.c (get_link_name): Don't ever use the stat field st_size as a
buffer size. Too many systems don't set it properly for mount points.
Instead, use a fixed-length buffer. From Michael Joosten
<joost@ori.CAdlab.DE>.
+ * cp.c (copy): Ditto.
Mon Jul 19 17:39:01 1993 Jim Meyering (meyering@comco.com)
diff --git a/old/fileutils/NEWS b/old/fileutils/NEWS
index 4b71f42e6..16246d08f 100644
--- a/old/fileutils/NEWS
+++ b/old/fileutils/NEWS
@@ -1,3 +1,8 @@
+Major changes in release 3.9:
+* ls and cp can handle mount points on more systems
+* cp, mkdir, and rmdir long option --path renamed to --parents; --path
+ will still work for a while
+
Major changes in release 3.8:
* install isn't as likely to produce spurious errors
* avoid redundant compilations for `dir' and `vdir';
diff --git a/src/cp.c b/src/cp.c
index c782d611d..7ba654679 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -133,6 +133,7 @@ static struct option const long_opts[] =
{"link", no_argument, NULL, 'l'},
{"no-dereference", no_argument, &flag_dereference, 0},
{"one-file-system", no_argument, &flag_one_file_system, 1},
+ {"parents", no_argument, &flag_path, 1},
{"path", no_argument, &flag_path, 1},
{"preserve", no_argument, &flag_preserve, 1},
{"recursive", no_argument, NULL, 'R'},
@@ -358,7 +359,7 @@ do_copy (argc, argv)
dst_path = xmalloc (strlen (dest) + strlen (arg) + 2);
stpcpy (stpcpy (stpcpy (dst_path, dest), "/"), arg);
- /* For --path, we have to make sure that the directory
+ /* For --parents, we have to make sure that the directory
dirname (dst_path) exists. We may have to create a few
leading directories. */
parent_exists = !make_path (dst_path,
@@ -407,9 +408,32 @@ do_copy (argc, argv)
}
else if (argc - optind == 2)
{
+ char *dst_path;
+ char *source;
+ struct stat source_stats;
+
if (flag_path)
usage ("when preserving paths, last argument must be a directory");
- return copy (argv[optind], dest, new_dst, 0, (struct dir_list *) 0);
+
+ source = argv[optind];
+
+ if (dest[strlen (dest) - 1] == '/'
+ && lstat (source, &source_stats) == 0
+ && !S_ISDIR (source_stats.st_mode))
+ {
+ char *base;
+
+ strip_trailing_slashes (source);
+ base = basename (source);
+ dst_path = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1);
+ stpcpy (stpcpy (stpcpy (dst_path, dest), "/"), base);
+ }
+ else
+ {
+ dst_path = dest;
+ }
+
+ return copy (argv[optind], dst_path, new_dst, 0, (struct dir_list *) 0);
}
else
usage ("when copying multiple files, last argument must be a directory");
@@ -711,17 +735,12 @@ copy (src_path, dst_path, new_dst, device, ancestors)
}
else
#ifdef S_ISLNK
-#ifdef _AIX
-#define LINK_BUF PATH_MAX
-#else
-#define LINK_BUF src_sb.st_size
-#endif
if (S_ISLNK (src_type))
{
- char *link_val = (char *) alloca (LINK_BUF + 1);
+ char link_val[PATH_MAX + 1];
int link_size;
- link_size = readlink (src_path, link_val, LINK_BUF);
+ link_size = readlink (src_path, link_val, sizeof (link_val) - 1);
if (link_size < 0)
{
error (0, errno, "cannot read symbolic link `%s'", src_path);
@@ -801,7 +820,7 @@ un_backup:
}
/* Ensure that the parent directory of CONST_DIRPATH exists, for
- the --path option.
+ the --parents option.
SRC_OFFSET is the index in CONST_DIRPATH (which is a destination
path) of the beginning of the source directory name.
@@ -870,7 +889,7 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
{
/* This element of the path does not exist. We must set
*new_dst and new->is_new_dir inside this loop because,
- for example, in the command `cp --path ../a/../b/c e_dir',
+ for example, in the command `cp --parents ../a/../b/c e_dir',
make_path creates only e_dir/../a if ./b already exists. */
*new_dst = 1;
new->is_new_dir = 1;
@@ -924,7 +943,7 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
}
/* Ensure that the parent directories of CONST_DST_PATH have the
- correct protections, for the --path option. This is done
+ correct protections, for the --parents option. This is done
after all copying has been completed, to allow permissions
that don't include user write/execute.
@@ -934,7 +953,7 @@ make_path (const_dirpath, src_offset, mode, verbose_fmt_string,
ATTR_LIST is a null-terminated linked list of structures that
indicates the end of the filename of each intermediate directory
in CONST_DST_PATH that may need to have its attributes changed.
- The command `cp --path --preserve a/b/c d/e_dir' changes the
+ The command `cp --parents --preserve a/b/c d/e_dir' changes the
attributes of the directories d/e_dir/a and d/e_dir/a/b to match
the corresponding source directories regardless of whether they
existed before the `cp' command was given.
diff --git a/src/ls.c b/src/ls.c
index adaab8aef..1b562be8c 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1081,7 +1081,7 @@ get_link_name (filename, f)
/* Some automounters give incorrect st_size for mount points.
I can't think of a good workaround for it, though. */
- linksize = readlink (filename, linkbuf, sizeof (linkbuf));
+ linksize = readlink (filename, linkbuf, sizeof (linkbuf) - 1);
if (linksize < 0)
{
error (0, errno, "%s", filename);
diff --git a/src/mv.c b/src/mv.c
index 5b6929100..220e14fda 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -58,6 +58,7 @@ int yesno ();
void error ();
void strip_trailing_slashes ();
int eaccess_stat ();
+char *stpcpy ();
static int copy_reg ();
static int do_move ();
@@ -188,6 +189,17 @@ main (argc, argv)
exit (errors);
}
+/* If PATH is an existing directory, return nonzero, else 0. */
+
+static int
+is_real_dir (path)
+ char *path;
+{
+ struct stat stats;
+
+ return lstat (path, &stats) == 0 && S_ISDIR (stats.st_mode);
+}
+
/* Move file SOURCE onto DEST. Handles the case when DEST is a directory.
Return 0 if successful, 1 if an error occurred. */
@@ -198,7 +210,8 @@ movefile (source, dest)
{
strip_trailing_slashes (source);
- if (isdir (dest))
+ if ((dest[strlen (dest) - 1] == '/' && !is_real_dir (source))
+ || isdir (dest))
{
/* Target is a directory; build full target filename. */
char *base;
@@ -206,7 +219,7 @@ movefile (source, dest)
base = basename (source);
new_dest = (char *) alloca (strlen (dest) + 1 + strlen (base) + 1);
- sprintf (new_dest, "%s/%s", dest, base);
+ stpcpy (stpcpy (stpcpy (new_dest, dest), "/"), base);
return do_move (source, new_dest);
}
else
diff --git a/src/rm.c b/src/rm.c
index 607b23f64..3f331e437 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -346,7 +346,8 @@ clear_directory (statp)
int pathname_length; /* Length of `pathname'. */
ino_t *inode_space; /* Copy of directory's inodes. */
ino_t *inodep; /* Current entry in `inode_space'. */
- unsigned inode_size; /* Bytes allocated for `inode_space'. */
+ unsigned n_inodes_allocated; /* There is space for this many inodes
+ in `inode_space'. */
int err = 0; /* Return status. */
struct pathstack pathframe; /* New top of stack. */
struct pathstack *pp; /* Temporary. */
@@ -354,8 +355,8 @@ clear_directory (statp)
name_size = statp->st_size;
name_space = (char *) xmalloc (name_size);
- inode_size = statp->st_size;
- inode_space = (ino_t *) xmalloc (inode_size);
+ n_inodes_allocated = (statp->st_size + sizeof (ino_t) - 1) / sizeof (ino_t);
+ inode_space = (ino_t *) xmalloc (n_inodes_allocated * sizeof (ino_t));
do
{
@@ -398,12 +399,13 @@ clear_directory (statp)
}
namep = stpcpy (namep, dp->d_name) + 1;
- if (inodep == inode_space + inode_size)
+ if (inodep == inode_space + n_inodes_allocated)
{
ino_t *new_inode_space;
- inode_size += 1024;
- new_inode_space = (ino_t *) xrealloc (inode_space, inode_size);
+ n_inodes_allocated += 1024;
+ new_inode_space = (ino_t *) xrealloc (inode_space,
+ n_inodes_allocated * sizeof (ino_t));
inodep += new_inode_space - inode_space;
inode_space = new_inode_space;
}