restore: improve error handling
This commit is contained in:
parent
ae776521b0
commit
42c40d399b
@ -1,21 +1,21 @@
|
|||||||
echo Starting Restorecopy >2
|
echo Starting Restorecopy >&2
|
||||||
read args
|
read args
|
||||||
read paths
|
read paths
|
||||||
echo Arguments: $args >2
|
echo Arguments: $args >&2
|
||||||
echo Paths: $paths >2
|
echo Paths: $paths >&2
|
||||||
if [ -f "$args" ] ; then
|
if [ -f "$args" ] ; then
|
||||||
echo "Performing restore from backup file $args" >2
|
echo "Performing restore from backup file $args" >&2
|
||||||
TARGET="$args"
|
TARGET="$args"
|
||||||
echo "Copying $TARGET to STDOUT" >2
|
echo "Copying $TARGET to STDOUT" >&2
|
||||||
/usr/lib/qubes/tar2qfile $TARGET $paths
|
/usr/lib/qubes/tar2qfile $TARGET $paths
|
||||||
else
|
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`
|
COMMAND=`echo $args | cut -d ' ' -f 1`
|
||||||
TYPE=`type -t $COMMAND`
|
TYPE=`type -t $COMMAND`
|
||||||
if [ "$TYPE" == "file" ] ; then
|
if [ "$TYPE" == "file" ] ; then
|
||||||
tmpdir=`mktemp -d`
|
tmpdir=`mktemp -d`
|
||||||
mkfifo $tmpdir/backup-data
|
mkfifo $tmpdir/backup-data
|
||||||
echo "Redirecting $args to STDOUT" >2
|
echo "Redirecting $args to STDOUT" >&2
|
||||||
# Parsing args to handle quotes correctly
|
# Parsing args to handle quotes correctly
|
||||||
# Dangerous method if args are uncontrolled
|
# Dangerous method if args are uncontrolled
|
||||||
eval "set -- $args"
|
eval "set -- $args"
|
||||||
@ -28,7 +28,8 @@ else
|
|||||||
rmdir $tmpdir
|
rmdir $tmpdir
|
||||||
exit $retcode
|
exit $retcode
|
||||||
else
|
else
|
||||||
echo "Invalid command $COMMAND" >2
|
echo "Invalid command $COMMAND" >&2
|
||||||
exit 1
|
exit 2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -863,24 +863,27 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr,"Parsing file %s\n",entry);
|
fprintf(stderr,"Parsing file %s\n",entry);
|
||||||
|
|
||||||
fd = open(entry, O_RDONLY);
|
fd = open(entry, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
fprintf(stderr,"Error opening file %s\n",entry);
|
fprintf(stderr,"Error opening file %s\n",entry);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
// At least two arguments can be found in the command line
|
// At least two arguments can be found in the command line
|
||||||
// (process name and the file to extract)
|
// (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
|
// No argument specified. Use STDIN
|
||||||
fprintf(stderr,"Using STDIN\n");
|
fprintf(stderr,"Using STDIN\n");
|
||||||
set_block(0);
|
set_block(0);
|
||||||
// If at least one argument has been found ( process name and - )
|
// If at least one argument has been found ( process name and - )
|
||||||
if (use_stdin)
|
if (use_stdin)
|
||||||
tar_file_processor(fileno(stdin), argc-2, argv[2]);
|
tar_file_processor(fileno(stdin), argc, argv);
|
||||||
else
|
else
|
||||||
tar_file_processor(fileno(stdin), argc-1, argv[1]);
|
tar_file_processor(fileno(stdin), argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user