summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-08-08 19:47:33 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-08-08 19:47:33 +0300
commitf653a2bd71d7e340f802dd76d432ed399ddd2d0e (patch)
tree6031765604786ac383014fed865ecb1412e54b14
parent20ecc7e634e41dd282d16739f17efe5e81fb2e98 (diff)
downloadpaxutils-f653a2bd71d7e340f802dd76d432ed399ddd2d0e.tar.gz
Improve genfile --run
* tests/genfile.c: Change the use of --run option. Implement --unlink action. * doc/genfile.texi: Document changes in genfile
-rw-r--r--doc/genfile.texi69
-rw-r--r--tests/genfile.c46
2 files changed, 80 insertions, 35 deletions
diff --git a/doc/genfile.texi b/doc/genfile.texi
index f9ef870..b37e26e 100644
--- a/doc/genfile.texi
+++ b/doc/genfile.texi
@@ -1,5 +1,5 @@
@c This is part of the paxutils manual.
-@c Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+@c Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
@c Written by Sergey Poznyakoff
@c This file is distributed under GFDL 1.1 or any later version
@c published by the Free Software Foundation.
@@ -268,31 +268,14 @@ commands when some of the files change during archiving. It is an
experimental mode.
The @samp{Exec Mode} is toggled by @option{--run} command line
-option (or its alias @option{-r}). The argument to this option gives
-the command line to be executed. The actual command line is
-constructed by inserting @option{--checkpoint} option between the
-command name and its first argument (if any). Due to this, the
-argument to @option{--run} may not use traditional @command{tar}
-option syntax, i.e., the following is wrong:
+option (or its alias @option{-r}). The non-optional arguments to
+@command{getopt} give the command line to be executed. Normally,
+it should contain at least the @option{--checkpoint} option.
-@smallexample
-# Wrong!
-genfile --run 'tar cf foo bar'
-@end smallexample
-
-@noindent
-
-Use the following syntax instead:
-
-@smallexample
-genfile --run 'tar -cf foo bar'
-@end smallexample
-
- The rest of command line after @option{--run} or its equivalent
-specifies checkpoint values and actions to be executed upon reaching
-them. Checkpoint values are introduced with @option{--checkpoint}
-command line option. Argument to this option is the number of
-checkpoint in decimal.
+ A set of options is provided for defining checkpoint values and
+actions to be executed upon reaching them. Checkpoint values are
+introduced with the @option{--checkpoint} command line
+option. Argument to this option is the number of checkpoint in decimal.
Any number of @dfn{actions} may be specified after a
checkpoint. Available actions are
@@ -316,7 +299,9 @@ an almost arbitrary format (@pxref{Date input formats}).
@item --exec @var{command}
Execute given shell command.
-
+
+@item --unlink @var{file}
+ Unlink the @var{file}.
@end table
Option @option{--verbose} instructs @command{genfile} to print on
@@ -329,3 +314,35 @@ connected to descriptor 1. All messages it prints to file descriptor
error.
@command{Genfile} exits with the exit status of the executed command.
+
+ For compatibility with previous @command{genfile} versions, the
+@option{--run} option takes an optional argument. If used this way,
+its argument supplies the command line to be executed. There should
+be no non-optional arguments in the @command{genfile} command line.
+
+ The actual command line is constructed by inserting
+the @option{--checkpoint} option between the command name and its
+first argument (if any). Due to this, the argument to @option{--run}
+may not use traditional @command{tar} option syntax, i.e., the
+following is wrong:
+
+@smallexample
+# Wrong!
+genfile --run='tar cf foo bar'
+@end smallexample
+
+@noindent
+
+Use the following syntax instead:
+
+@smallexample
+genfile --run='tar -cf foo bar' @var{actions}...
+@end smallexample
+
+The above command line is equivalent to
+
+@smallexample
+genfile @var{actions}... -- tar -cf foo bar
+@end smallexample
+
+Notice, that the use of compatibility mode is deprecated.
diff --git a/tests/genfile.c b/tests/genfile.c
index 3cceb02..7ebeddf 100644
--- a/tests/genfile.c
+++ b/tests/genfile.c
@@ -99,6 +99,7 @@ char *buffer;
/* Number of arguments and argument vector for mode == mode_exec */
int exec_argc;
char **exec_argv;
+char *checkpoint_option;
/* Time for --touch option */
struct timespec touch_time;
@@ -119,6 +120,7 @@ static char doc[] = N_("genfile manipulates data files for GNU paxutils test sui
#define OPT_DATE 261
#define OPT_VERBOSE 262
#define OPT_SEEK 263
+#define OPT_UNLINK 264
static struct argp_option options[] = {
#define GRP 0
@@ -159,8 +161,8 @@ static struct argp_option options[] = {
{NULL, 0, NULL, 0,
N_("Synchronous execution options:"), GRP},
- {"run", 'r', N_("COMMAND"), 0,
- N_("Execute given COMMAND. Useful with --checkpoint and one of --cut, --append, --touch"),
+ {"run", 'r', N_("OPTION"), OPTION_ARG_OPTIONAL,
+ N_("Execute ARGS. Useful with --checkpoint and one of --cut, --append, --touch, --unlink"),
GRP+1 },
{"checkpoint", OPT_CHECKPOINT, N_("NUMBER"), 0,
N_("Perform given action (see below) upon reaching checkpoint NUMBER"),
@@ -189,6 +191,9 @@ static struct argp_option options[] = {
{"exec", OPT_EXEC, N_("COMMAND"), 0,
N_("Execute COMMAND"),
GRP+1 },
+ {"unlink", OPT_UNLINK, N_("FILE"), 0,
+ N_("Unlink FILE"),
+ GRP+1 },
#undef GRP
{ NULL, }
};
@@ -333,7 +338,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
case 'r':
mode = mode_exec;
- argcv_get (arg, "", NULL, &exec_argc, &exec_argv);
+ if (arg)
+ {
+ argcv_get (arg, "", NULL, &exec_argc, &exec_argv);
+ checkpoint_option = "--checkpoint";
+ }
break;
case 'T':
@@ -363,6 +372,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
case OPT_TRUNCATE:
case OPT_TOUCH:
case OPT_EXEC:
+ case OPT_UNLINK:
reg_action (key, arg);
break;
@@ -685,6 +695,11 @@ exec_checkpoint (struct action *p)
system (p->name);
break;
+ case OPT_UNLINK:
+ if (unlink (p->name))
+ error (0, errno, _("cannot unlink `%s'"), p->name);
+ break;
+
default:
abort ();
}
@@ -730,11 +745,17 @@ exec_command (void)
/* Insert --checkpoint option.
FIXME: This assumes that exec_argv does not use traditional tar options
- (without dash) */
- exec_argc++;
- exec_argv = xrealloc (exec_argv, (exec_argc + 1) * sizeof (*exec_argv));
- memmove (exec_argv+2, exec_argv+1, (exec_argc - 1) * sizeof (*exec_argv));
- exec_argv[1] = "--checkpoint";
+ (without dash).
+ FIXME: There is no way to set checkpoint argument (granularity).
+ */
+ if (checkpoint_option)
+ {
+ exec_argc++;
+ exec_argv = xrealloc (exec_argv, (exec_argc + 1) * sizeof (*exec_argv));
+ memmove (exec_argv+2, exec_argv+1,
+ (exec_argc - 1) * sizeof (*exec_argv));
+ exec_argv[1] = checkpoint_option;
+ }
#ifdef SIGCHLD
/* System V fork+wait does not work if SIGCHLD is ignored. */
@@ -760,7 +781,7 @@ exec_command (void)
setenv ("LC_ALL", "POSIX", 1);
execvp (exec_argv[0], exec_argv);
- error (EXIT_FAILURE, errno, "execvp");
+ error (EXIT_FAILURE, errno, "execvp %s", exec_argv[0]);
}
/* Master */
@@ -872,6 +893,13 @@ main (int argc, char **argv)
break;
case mode_exec:
+ if (!checkpoint_option)
+ {
+ exec_argc = argc;
+ exec_argv = argv;
+ }
+ else if (argc)
+ error (EXIT_FAILURE, 0, _("too many arguments"));
exec_command ();
break;