From 6fb00021456f948ec6231bdd13b895fa66386bd3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 30 Dec 2023 18:37:35 +0300 Subject: [PATCH] reworked path handling... Signed-off-by: Alex A. Naanou --- .pct-helpers | 12 ++++++++++++ pct-push-r | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.pct-helpers b/.pct-helpers index 3a20cf9..5e7b3a0 100644 --- a/.pct-helpers +++ b/.pct-helpers @@ -126,6 +126,18 @@ hostname2ct(){ } +#---------------------------------------------------------------------- + +normpath(){ + echo $1 \ + | sed \ + -e 's/\/\+/\//g' \ + -e 's/\/.\//\//g' \ + -e 's/[^\/]\+\/\.\.//g' \ + -e 's/\/\+/\//g' \ + -e 's/\/\.$/\//g' +} + #---------------------------------------------------------------------- # vim:set ts=4 sw=4 nowrap : diff --git a/pct-push-r b/pct-push-r index 8cdf615..3a4f7e7 100644 --- a/pct-push-r +++ b/pct-push-r @@ -34,7 +34,7 @@ to=$3 # get from path relative to working directory... if [[ ${from:0:1} != '/' ]] ; then - from="$(pwd)/${from}" + from="$(normpath "$(pwd)/${from}")" fi @@ -52,9 +52,11 @@ done local files=($(find "$from" -type f)) for file in "${files[@]}" ; do file=${file#${from}} + f=$(normpath "${from}/${file}") + t=$(normpath "${to}/${file}") [ $QUIET ] \ - || echo "copy: \"${from}/${file}\" -> $id:\"${to}/${file}\"" - pct push $id "${from}/${file}" "${to}/${file}" + || echo "copy: \"$f\" -> $id:\"$t\"" + pct push $id "$f" "$t" done