Skip to content

Commit 62c781d

Browse files
committed
handle files of any path
1 parent f12728a commit 62c781d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

vackup

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ vackup load IMAGE VOLUME
4343
EOF
4444
}
4545

46+
fulldirname() {
47+
DIRECTORY=$(dirname "$1")
48+
49+
case "$DIRECTORY" in
50+
\/*) ;;
51+
\.*) ;& # fallthrough
52+
*) DIRECTORY="$(pwd)/$DIRECTORY" ;;
53+
esac
54+
DIRECTORY=$(readlink -m "$DIRECTORY")
55+
56+
echo "$DIRECTORY"
57+
}
58+
4659
if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
4760
usage
4861
exit 0
@@ -66,12 +79,13 @@ cmd_export() {
6679

6780
# TODO: check if file exists on host, if it does
6881
# create a option for overwrite and check if that's set
69-
# TODO: if FILE_NAME starts with / we need to error out
70-
# unless we can translate full file paths
82+
83+
DIRECTORY=$(fulldirname "$FILE_NAME")
84+
FILE_NAME=$(basename "$FILE_NAME")
7185

7286
if ! docker run --rm \
7387
-v "$VOLUME_NAME":/vackup-volume \
74-
-v "$(pwd)":/vackup \
88+
-v "$DIRECTORY":/vackup \
7589
busybox \
7690
tar -zcvf /vackup/"$FILE_NAME" /vackup-volume;
7791
then
@@ -100,12 +114,13 @@ cmd_import() {
100114

101115
# TODO: check if file exists on host, if it does
102116
# create a option for overwrite and check if that's set
103-
# TODO: if FILE_NAME starts with / we need to error out
104-
# unless we can translate full file paths
117+
118+
DIRECTORY=$(fulldirname "$FILE_NAME")
119+
FILE_NAME=$(basename "$FILE_NAME")
105120

106121
if ! docker run --rm \
107122
-v "$VOLUME_NAME":/vackup-volume \
108-
-v "$(pwd)":/vackup \
123+
-v "$DIRECTORY":/vackup \
109124
busybox \
110125
tar -xvzf /vackup/"$FILE_NAME" -C /;
111126
then

0 commit comments

Comments
 (0)