[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I have an enhancement for ginstall
From: |
Rich Megginson |
Subject: |
I have an enhancement for ginstall |
Date: |
Wed, 26 Sep 2001 14:20:17 -0600 |
I apologize if this is not the correct place to post this, but I did not want
to send mail directly to the maintainers and the
mail.gnu.org website is apparently down right now.
I really want an install that will create the destination directory AND install
the files into it in a single command.
e.g. install -C file1 ... fileN /a/long/directory/path/that/does/not/exist
-C (--createdir) - assume the last argument is a directory. If that directory
does not exist, create it and any parent
directories. Then copy the other file arguments into that directory.
Here are the diffs and the new file.
###########################################################
man/ginstall.1
--- ginstall.1.orig Wed Sep 26 11:45:58 2001
+++ ginstall.1 Wed Sep 26 12:01:50 2001
@@ -26,6 +26,10 @@ like \fB\-\-backup\fR but does not accep
\fB\-c\fR
(ignored)
.TP
+\fB\-C\fR, \fB\-\-createdir\fR
+assume DEST is a directory and create it and all
+components of DEST
+.TP
\fB\-d\fR, \fB\-\-directory\fR
treat all arguments as directory names; create all
components of the specified directories
###########################################################
tests/install/Makefile.am
--- Makefile.am Wed Sep 26 11:22:05 2001
+++ Makefile.am.orig Wed Sep 26 11:22:31 2001
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in -*-Makefile-*-.
AUTOMAKE_OPTIONS = 1.3 gnits
-TESTS = basic-1 create-leading create-path
+TESTS = basic-1 create-leading
EXTRA_DIST = $(TESTS)
TESTS_ENVIRONMENT = \
PATH=`pwd`/../../src:$$PATH
###########################################################
tests/install/create-path
#! /bin/sh
# Test -C option.
# Note that the tests below use `ginstall', not install, because
# that's the name of the binary in ../../src.
if test "$VERBOSE" = yes; then
set -x
ginstall --version
fi
. $srcdir/../envvar-check
pwd=`pwd`
dir=install-C$$
trap "cd $pwd; rm -rf $dir" 0 1 2 3 15
mkdir $dir
fail=0
cd $dir
file1=file1
file2=file2
echo foo1 > $file1
echo foo2 > $file2
ginstall -C $file1 $file2 no-dir1/no-dir2/dest || fail=1
test -d no-dir1/no-dir2/dest || fail=1
test -r no-dir1/no-dir2/dest/$file1 || fail=1
test -r no-dir1/no-dir2/dest/$file2 || fail=1
ginstall -C $file1 no-dir3/no-dir4/dest || fail=1
test -d no-dir3/no-dir4/dest || fail=1
test -r no-dir3/no-dir4/dest/$file1 || fail=1
exit $fail
###########################################################
doc/fileutils.texi
--- fileutils.texi.orig Wed Sep 26 11:25:55 2001
+++ fileutils.texi Wed Sep 26 11:45:22 2001
@@ -1698,6 +1698,15 @@ Make a backup of each file that would ot
@opindex -c
Ignored; for compatibility with old Unix versions of @code{install}.
address@hidden -C
address@hidden --createdir
address@hidden -C
address@hidden --createdir
address@hidden parent directories, creating missing
address@hidden leading directories, creating missing
+Assume the last argument is a directory and create it and any missing
+parent directories if they do not exist.
+
@item -d
@itemx --directory
@opindex -d
###########################################################
src/install.c
--- install.c.orig Wed Sep 26 10:21:49 2001
+++ install.c Wed Sep 26 11:04:59 2001
@@ -88,7 +88,8 @@ static int change_attributes PARAMS ((co
static int copy_file PARAMS ((const char *from, const char *to,
const struct cp_options *x));
static int install_file_to_path PARAMS ((const char *from, const char *to,
- const struct cp_options *x));
+ const struct cp_options *x,
+ int create_path));
static int install_file_in_dir PARAMS ((const char *from, const char *to_dir,
const struct cp_options *x));
static int install_file_in_file PARAMS ((const char *from, const char *to,
@@ -124,9 +125,13 @@ static int strip_files;
/* If nonzero, install a directory instead of a regular file. */
static int dir_arg;
+/* If nonzero, assume last arg is a directory and create it */
+static int create_path;
+
static struct option const long_options[] =
{
{"backup", optional_argument, NULL, 'b'},
+ {"createdir", no_argument, NULL, 'C'},
{"directory", no_argument, NULL, 'd'},
{"group", required_argument, NULL, 'g'},
{"mode", required_argument, NULL, 'm'},
@@ -205,13 +210,14 @@ main (int argc, char **argv)
group_name = NULL;
strip_files = 0;
dir_arg = 0;
+ create_path = 0;
umask (0);
/* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
we'll actually use backup_suffix_string. */
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
- while ((optc = getopt_long (argc, argv, "bcsDdg:m:o:pvV:S:", long_options,
+ while ((optc = getopt_long (argc, argv, "bCcsDdg:m:o:pvV:S:", long_options,
NULL)) != -1)
{
switch (optc)
@@ -231,6 +237,9 @@ main (int argc, char **argv)
if (optarg)
version_control_string = optarg;
break;
+ case 'C':
+ create_path = 1;
+ break;
case 'c':
break;
case 's':
@@ -320,8 +329,9 @@ main (int argc, char **argv)
if (n_files == 2)
{
- if (mkdir_and_install)
- errors = install_file_to_path (file[0], file[1], &x);
+ if (mkdir_and_install || create_path)
+ errors = install_file_to_path (file[0], file[1], &x,
+ create_path);
else if (!isdir (file[1]))
errors = install_file_in_file (file[0], file[1], &x);
else
@@ -331,7 +341,7 @@ main (int argc, char **argv)
{
int i;
const char *dest = file[n_files - 1];
- if (!isdir (dest))
+ if (!isdir (dest) && !create_path)
{
error (0, 0,
_("installing multiple files, but last argument, %s \
@@ -341,7 +351,11 @@ is not a directory"),
}
for (i = 0; i < n_files - 1; i++)
{
- errors |= install_file_in_dir (file[i], dest, &x);
+ if (create_path)
+ errors |= install_file_to_path (file[i], dest, &x,
+ create_path);
+ else
+ errors |= install_file_in_dir (file[i], dest, &x);
}
}
}
@@ -354,13 +368,21 @@ is not a directory"),
static int
install_file_to_path (const char *from, const char *to,
- const struct cp_options *x)
+ const struct cp_options *x, int create_path)
{
char *dest_dir;
int fail = 0;
- dest_dir = dir_name (to);
+ /* If the create_path is TRUE, this means that to is a directory,
+ and create it if it does not exist.
+ Otherwise, to is a file.
+ */
+ if (create_path)
+ dest_dir = xstrdup (to);
+ else
+ dest_dir = dir_name (to);
+
/* check to make sure this is a path (not install a b ) */
if (!STREQ (dest_dir, ".")
&& !isdir (dest_dir))
@@ -375,7 +397,12 @@ install_file_to_path (const char *from,
}
if (fail == 0)
- fail = install_file_in_file (from, to, x);
+ {
+ if (create_path)
+ fail = install_file_in_dir (from, to, x);
+ else
+ fail = install_file_in_file (from, to, x);
+ }
free (dest_dir);
@@ -611,6 +638,8 @@ In the third format, create all componen
--backup[=CONTROL] make a backup of each existing destination file\n\
-b like --backup but does not accept an argument\n\
-c (ignored)\n\
+ -C, --createdir treat the last argument as a directory name and create\n\
+ all components of it that do not exist\n\
-d, --directory treat all arguments as directory names; create all\n\
components of the specified directories\n\
-D create all leading components of DEST except the last,\n\
###########################################################
smime.p7s
Description: S/MIME Cryptographic Signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- I have an enhancement for ginstall,
Rich Megginson <=