Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle files of any path #22

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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