Skip to content

Commit

Permalink
Merge pull request #22 from Guiorgy/handle-files-of-any-path
Browse files Browse the repository at this point in the history
handle files of any path
  • Loading branch information
BretFisher authored Nov 1, 2024
2 parents f62e2bb + b0dbf5f commit 2a8a731
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions vackup
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ error() {
handle_error $LINE_NUMBER $CODE
}

fulldirname() {
DIRECTORY=$(dirname "$1")

case "$DIRECTORY" in
/*) ;;
.*) ;& # fallthrough
*) DIRECTORY="$(pwd)/$DIRECTORY" ;;
esac
DIRECTORY=$(readlink -m "$DIRECTORY")

echo "$DIRECTORY"
}

if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
usage
exit 0
Expand All @@ -98,12 +111,13 @@ cmd_export() {

# TODO: check if file exists on host, if it does
# create a option for overwrite and check if that's set
# TODO: if FILE_NAME starts with / we need to error out
# unless we can translate full file paths

DIRECTORY=$(fulldirname "$FILE_NAME")
FILE_NAME=$(basename "$FILE_NAME")

if ! docker run --rm \
-v "$VOLUME_NAME":/vackup-volume \
-v "$(pwd)":/vackup \
-v "$DIRECTORY":/vackup \
busybox \
tar -zcvf /vackup/"$FILE_NAME" /vackup-volume;
then
Expand Down Expand Up @@ -137,12 +151,12 @@ cmd_import() {
exit 1
fi

# TODO: if FILE_NAME starts with / we need to error out
# unless we can translate full file paths
DIRECTORY=$(fulldirname "$FILE_NAME")
FILE_NAME=$(basename "$FILE_NAME")

if ! docker run --rm \
-v "$VOLUME_NAME":/vackup-volume \
-v "$(pwd)":/vackup \
-v "$DIRECTORY":/vackup \
busybox \
tar -xvzf /vackup/"$FILE_NAME" -C /;
then
Expand Down

0 comments on commit 2a8a731

Please sign in to comment.