dk: vérifier que le répertoire destination existe avant rsync

This commit is contained in:
Jephté Clain 2020-04-28 16:41:47 +04:00
parent c147a0cef3
commit e2b2f49214
1 changed files with 26 additions and 8 deletions

34
dk
View File

@ -806,21 +806,39 @@ function build_update_apps() {
if [ -d "$SRC" ]; then
[ -n "$have_RSYNC_OPTS" ] || RSYNC_OPTS=(--delete --delete-excluded)
local -a rsync_opts; rsync_opts=(-a --exclude .git/ "${RSYNC_OPTS[@]}")
SRC="${SRC%/}/"
DEST="${DEST%/}/"
DEST="${DEST%/}"
if [ ! -d "$DEST" ]; then
# s'assurer que le répertoire parent existe
mkdir -p "$(dirname -- "$DEST")" || { eend; return 1; }
fi
DEST="$DEST/"
estep "Synchro $SRC --> $DEST"
rsync "${rsync_opts[@]}" "$SRC" "$DEST" || { eend; return 1; }
elif [ -f "$SRC" ]; then
[ -n "$have_RSYNC_OPTS" ] || RSYNC_OPTS=()
local -a rsync_opts; rsync_opts=(-a "${RSYNC_OPTS[@]}")
if [ "${DEST%/}" != "$DEST" -o -d "$DEST" ]; then
DEST="${DEST%/}/"
estep "Synchro $SRC --> $DEST"
rsync "${rsync_opts[@]}" "$SRC" "$DEST" || { eend; return 1; }
else
estep "Synchro $SRC --> $DEST"
rsync "${rsync_opts[@]}" "$SRC" "$DEST" || { eend; return 1; }
if [ "${DEST%/}" != "$DEST" -a ! -d "$DEST" ]; then
# on demande à ce que DEST soit un répertoire mais il
# n'existe pas: le créer
DEST="${DEST%/}"
mkdir -p "$DEST" || { eend; return 1; }
fi
if [ -d "$DEST" ]; then
DEST="$DEST/"
elif [ ! -f "$DEST" ]; then
# la destination n'existe pas: s'assurer que le répertoire
# parent existe
mkdir -p "$(dirname -- "$DEST")" || { eend; return 1; }
fi
estep "Synchro $SRC --> $DEST"
rsync "${rsync_opts[@]}" "$SRC" "$DEST" || { eend; return 1; }
else
eerror "$app: $SRC: répertoire/fichier introuvable"
eend; return 1