restore: improve error handling

This commit is contained in:
Olivier MEDOC 2013-11-19 13:35:51 +01:00 committed by Marek Marczykowski-Górecki
parent ae776521b0
commit 42c40d399b
2 changed files with 18 additions and 14 deletions

View File

@ -1,21 +1,21 @@
echo Starting Restorecopy >2
echo Starting Restorecopy >&2
read args
read paths
echo Arguments: $args >2
echo Paths: $paths >2
echo Arguments: $args >&2
echo Paths: $paths >&2
if [ -f "$args" ] ; then
echo "Performing restore from backup file $args" >2
echo "Performing restore from backup file $args" >&2
TARGET="$args"
echo "Copying $TARGET to STDOUT" >2
echo "Copying $TARGET to STDOUT" >&2
/usr/lib/qubes/tar2qfile $TARGET $paths
else
echo "Checking if arguments is matching a command" >2
echo "Checking if arguments is matching a command" >&2
COMMAND=`echo $args | cut -d ' ' -f 1`
TYPE=`type -t $COMMAND`
if [ "$TYPE" == "file" ] ; then
tmpdir=`mktemp -d`
mkfifo $tmpdir/backup-data
echo "Redirecting $args to STDOUT" >2
echo "Redirecting $args to STDOUT" >&2
# Parsing args to handle quotes correctly
# Dangerous method if args are uncontrolled
eval "set -- $args"
@ -28,7 +28,8 @@ else
rmdir $tmpdir
exit $retcode
else
echo "Invalid command $COMMAND" >2
exit 1
echo "Invalid command $COMMAND" >&2
exit 2
fi
fi

View File

@ -863,24 +863,27 @@ int main(int argc, char **argv)
fprintf(stderr,"Parsing file %s\n",entry);
fd = open(entry, O_RDONLY);
if (fd < 0)
if (fd < 0) {
fprintf(stderr,"Error opening file %s\n",entry);
exit(2);
}
// At least two arguments can be found in the command line
// (process name and the file to extract)
tar_file_processor(fd, argc-2, argv[2]);
tar_file_processor(fd, argc, argv);
break;
}
}
if (i <= 1 || use_stdin == 1) {
if (use_stdin == 1) {
// No argument specified. Use STDIN
fprintf(stderr,"Using STDIN\n");
set_block(0);
// If at least one argument has been found ( process name and - )
if (use_stdin)
tar_file_processor(fileno(stdin), argc-2, argv[2]);
tar_file_processor(fileno(stdin), argc, argv);
else
tar_file_processor(fileno(stdin), argc-1, argv[1]);
tar_file_processor(fileno(stdin), argc, argv);
}