Skip to content

Commit b0dbf5f

Browse files
committed
handle files of any path
1 parent f62e2bb commit b0dbf5f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

vackup

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ error() {
7878
handle_error $LINE_NUMBER $CODE
7979
}
8080

81+
fulldirname() {
82+
DIRECTORY=$(dirname "$1")
83+
84+
case "$DIRECTORY" in
85+
/*) ;;
86+
.*) ;& # fallthrough
87+
*) DIRECTORY="$(pwd)/$DIRECTORY" ;;
88+
esac
89+
DIRECTORY=$(readlink -m "$DIRECTORY")
90+
91+
echo "$DIRECTORY"
92+
}
93+
8194
if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
8295
usage
8396
exit 0
@@ -98,12 +111,13 @@ cmd_export() {
98111

99112
# TODO: check if file exists on host, if it does
100113
# create a option for overwrite and check if that's set
101-
# TODO: if FILE_NAME starts with / we need to error out
102-
# unless we can translate full file paths
114+
115+
DIRECTORY=$(fulldirname "$FILE_NAME")
116+
FILE_NAME=$(basename "$FILE_NAME")
103117

104118
if ! docker run --rm \
105119
-v "$VOLUME_NAME":/vackup-volume \
106-
-v "$(pwd)":/vackup \
120+
-v "$DIRECTORY":/vackup \
107121
busybox \
108122
tar -zcvf /vackup/"$FILE_NAME" /vackup-volume;
109123
then
@@ -137,12 +151,12 @@ cmd_import() {
137151
exit 1
138152
fi
139153

140-
# TODO: if FILE_NAME starts with / we need to error out
141-
# unless we can translate full file paths
154+
DIRECTORY=$(fulldirname "$FILE_NAME")
155+
FILE_NAME=$(basename "$FILE_NAME")
142156

143157
if ! docker run --rm \
144158
-v "$VOLUME_NAME":/vackup-volume \
145-
-v "$(pwd)":/vackup \
159+
-v "$DIRECTORY":/vackup \
146160
busybox \
147161
tar -xvzf /vackup/"$FILE_NAME" -C /;
148162
then

0 commit comments

Comments
 (0)