From 769a800bc125c6968ae5fdb2729292bf0fdab211 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Sun, 11 Feb 2007 00:45:04 +0000 Subject: [PATCH] Remove the --source and --dest "options" from vclone, both are required. Catch error conditions about the arguments in vclone. Attempt to figure out where the source if it's not a directory, and make sure it is one before running vclone. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2494 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- scripts/vserver-build.clone | 16 ++++++++++------ src/vclone.c | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/scripts/vserver-build.clone b/scripts/vserver-build.clone index 0c728a9..015b523 100644 --- a/scripts/vserver-build.clone +++ b/scripts/vserver-build.clone @@ -23,14 +23,12 @@ eval set -- "$tmp" DISTRIBUTION=: use_pkgmgmt= SOURCE= -declare -a OPTS=() while true; do case "$1" in -d) DISTRIBUTION=$2; shift;; --debug) set -x;; --pkgmgmt) use_pkgmgmt=1;; -s|--source) SOURCE=$2; shift;; - -o) OPTS=( "${OPTS[@]}" "$2" ); shift;; --) shift; break ;; *) echo "vserver-build.clone: internal error: unrecognized option '$1'" >&2 exit 1 @@ -39,11 +37,17 @@ while true; do shift done -if test -z "$SOURCE"; then - panic $"vserver-build.clone: --source argument required" +if test -d "$SOURCE"; then + : +elif test -d "$__CONFDIR/$SOURCE"; then + SOURCE=`getPhysicalDir "$__CONFDIR/$SOURCE/vdir"` +elif test -d "$__DEFAULT_VSERVERDIR/$SOURCE"; then + SOURCE=`getPhysicalDir "$__DEFAULT_VSERVERDIR/$SOURCE"` +else + SOURCE= fi -test -z "${OPTS[*]}" && OPTS=( -Hazx --numeric-ids ) +test -n "$SOURCE" || panic $"vserver-build.clone: valid --source argument required" getDistribution '' 1 @@ -59,7 +63,7 @@ setup_writeInitialFstab test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" -$_VCLONE --source "$SOURCE"/ --dest "$VDIR"/ +$_VCLONE "$SOURCE"/ "$VDIR"/ test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" diff --git a/src/vclone.c b/src/vclone.c index a9d2b2e..85c3c64 100644 --- a/src/vclone.c +++ b/src/vclone.c @@ -44,8 +44,6 @@ #define CMD_HELP 0x8000 #define CMD_VERSION 0x8001 -#define CMD_SOURCE 0x8002 -#define CMD_DEST 0x8003 struct WalkdownInfo { @@ -67,8 +65,6 @@ struct option const CMDLINE_OPTIONS[] = { { "help", no_argument, 0, CMD_HELP }, { "version", no_argument, 0, CMD_VERSION }, - { "source", required_argument, 0, CMD_SOURCE }, - { "dest", required_argument, 0, CMD_DEST }, { 0,0,0,0 } }; @@ -81,7 +77,7 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " --source --dest \n\n" + " \n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -160,6 +156,7 @@ int main(int argc, char *argv[]) .verbosity = 0, }; uint64_t res; + int num_args; global_args = &args; while (1) { @@ -170,8 +167,6 @@ int main(int argc, char *argv[]) switch (c) { case CMD_HELP : showHelp(1, argv[0], 0); case CMD_VERSION : showVersion(); - case CMD_SOURCE : ENSC_PI_SETSTR(global_info.src, optarg); break; - case CMD_DEST : ENSC_PI_SETSTR(global_info.dst, optarg); break; default : WRITE_MSG(2, "Try '"); WRITE_STR(2, argv[0]); @@ -181,6 +176,34 @@ int main(int argc, char *argv[]) } } + num_args = argc - optind; + if (num_args < 1) { + WRITE_MSG(2, "Source is missing; try '"); + WRITE_STR(2, argv[0]); + WRITE_MSG(2, " --help' for more information.\n"); + return EXIT_FAILURE; + } + else if (num_args < 2) { + WRITE_MSG(2, "Destination is missing; try '"); + WRITE_STR(2, argv[0]); + WRITE_MSG(2, " --help' for more information.\n"); + return EXIT_FAILURE; + } + else if (num_args > 2) { + WRITE_MSG(2, "Too many arguments; try '"); + WRITE_STR(2, argv[0]); + WRITE_MSG(2, " --help' for more information.\n"); + return EXIT_FAILURE; + } + else if (*argv[optind+1] != '/') { + WRITE_MSG(2, "The destination must be an absolute path; try '"); + WRITE_STR(2, argv[0]); + WRITE_MSG(2, " --help' for more information.\n"); + return EXIT_FAILURE; + } + ENSC_PI_SETSTR(global_info.src, argv[optind]); + ENSC_PI_SETSTR(global_info.dst, argv[optind+1]); + if (global_args->verbosity>3) WRITE_MSG(1, "Starting to traverse directories...\n"); -- 1.8.1.5