From 403b1d71a363482c5d8ad2ed414b6a6fb33128d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 8 May 2016 00:26:07 +0200 Subject: [PATCH] [fix] Prepend backup dir to relative path only and allow absolute in ynh_backup --- data/helpers.d/filesystem | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/data/helpers.d/filesystem b/data/helpers.d/filesystem index db12fb761..a02434572 100644 --- a/data/helpers.d/filesystem +++ b/data/helpers.d/filesystem @@ -3,7 +3,7 @@ CAN_BIND=${CAN_BIND:-1} # Mark a file or a directory for backup # Note: currently, SRCPATH will be copied or binded to DESTPATH # -# usage: ynh_backup srcdir destdir can_bind as_root +# usage: ynh_backup srcdir destdir to_bind no_root # | arg: srcdir - directory to bind or copy # | arg: destdir - mountpoint or destination directory # | arg: to_bind - 1 to bind mounting the directory if possible @@ -20,14 +20,10 @@ ynh_backup() { echo "Source path '${DESTPATH}' does not exist" >&2 return 1 } - [[ "${DESTPATH:0:1}" = "/" ]] && { - echo "Destination path should be relative" >&2 - return 1 - } # prepend the backup directory - [[ -z "${YNH_APP_BACKUP_DIR}" ]] || \ - DESTPATH="${YNH_APP_BACKUP_DIR}/${DESTPATH}" + [[ -n "${YNH_APP_BACKUP_DIR}" && "${DESTPATH:0:1}" != "/" ]] \ + && DESTPATH="${YNH_APP_BACKUP_DIR}/${DESTPATH}" [[ ! -e "${DESTPATH}" ]] || { echo "Destination path '${DESTPATH}' already exist" >&2 return 1 @@ -39,7 +35,7 @@ ynh_backup() { if sudo mount --rbind "${SRCPATH}" "${DESTPATH}"; then # try to remount destination directory as read-only - sudo mount -o remount,ro "${DESTPATH}" \ + sudo mount -o remount,ro "${DESTPATH}" >/dev/null 2>&1 \ || sudo mount -o remount,ro,bind "${SRCPATH}" "${DESTPATH}" \ || true return 0