From fe1eb5378093956acaaad0c7c5c070d71f98f8ca Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 19 Feb 2019 16:33:14 +0300 Subject: [PATCH] fixed duplicate filename handling... Signed-off-by: Alex A. Naanou --- scripts/process-archive.sh | 51 ++++++++++++------- .../media/img/my/work/process-archive.sh | 36 +++++++++++-- 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/scripts/process-archive.sh b/scripts/process-archive.sh index dd420324..68be081d 100755 --- a/scripts/process-archive.sh +++ b/scripts/process-archive.sh @@ -235,24 +235,7 @@ if [ -z $SKIP_PREVIEWS ] ; then find . -path '*hi-res (RAW)/*.jpg' -exec bash -c 'makepreview "$SIZE" "{}"' \; fi - # collect previews to one location... -jpg2dir(){ - FROM=$1 - TO=$2 - - FULL_TO=$2/`basename "$FROM"` - I=0 - - while [ -e "$FULL_TO" ] ; do - I=$((I + 1)) - FULL_TO=$2/`basename -s .jpg "$FROM"`_${I}.jpg - done - - cp -rl "$FROM" "$FULL_TO" -} -export -f jpg2dir - # XXX test!!! if ! [ -z "$COMMON_PREVIEWS" ] ; then if ! [ -e "./$COMMON_PREVIEWS" ] ; then @@ -265,9 +248,39 @@ if ! [ -z "$COMMON_PREVIEWS" ] ; then find . -type d \ -name 'preview (RAW)' \ -print \ - -exec bash -c 'jpg2dir "{}" "./$COMMON_PREVIEWS"' \; - #-exec cp -rl "{}" "./$COMMON_PREVIEWS" \; + -exec cp --backup=t -rl "{}" "./$COMMON_PREVIEWS" \; #-exec rm -rf "./$d" + + # cleanup filenames... (HACK) + # image.jpg -> image_3.jpg + # image.jpg.~3~ -> image_2.jpg + # image.jpg.~2~ -> image_1.jpg + # image.jpg.~1~ -> image.jpg + # + i=0 + while true ; do + i=$((i + 1)) + images=("$COMMON_PREVIEWS/preview (RAW)/"*.~$i~) + + # break if no matches... + if ! [ -e "${images[0]}" ] ; then + break + fi + + for img in "${images[@]}" ; do + # decrement... + # image.jpg.~(N)~ -> image_(N-1).jpg + mv "$img" "${img/.jpg.~${i}~/_$((i-1)).jpg}" + + # next image does not exist... + # image.jpg -> image_(N).jpg + # image_0.jpg -> image.jpg + if ! [ -e "${img/.jpg.~${i}~/.jpg.~$((i+1))~}" ] ; then + mv "${img/.jpg.~${i}~/.jpg}" "${img/.jpg.~${i}~/_$((i)).jpg}" + mv "${img/.jpg.~${i}~/_0.jpg}" "${img/.jpg.~${i}~/.jpg}" + fi + done + done fi diff --git a/ui (gen4)/archive/media/img/my/work/process-archive.sh b/ui (gen4)/archive/media/img/my/work/process-archive.sh index 2f8fa99e..68be081d 100755 --- a/ui (gen4)/archive/media/img/my/work/process-archive.sh +++ b/ui (gen4)/archive/media/img/my/work/process-archive.sh @@ -235,8 +235,6 @@ if [ -z $SKIP_PREVIEWS ] ; then find . -path '*hi-res (RAW)/*.jpg' -exec bash -c 'makepreview "$SIZE" "{}"' \; fi - - # collect previews to one location... # XXX test!!! if ! [ -z "$COMMON_PREVIEWS" ] ; then @@ -246,11 +244,43 @@ if ! [ -z "$COMMON_PREVIEWS" ] ; then #if [ -z $TOTAL ] ; then # export TOTAL=`find . -path '*hi-res (RAW)/*.jpg' | wc -l` #fi + # XXX BUG: this does not rename if target exists... find . -type d \ -name 'preview (RAW)' \ -print \ - -exec cp -rl "{}" "./$COMMON_PREVIEWS" \; + -exec cp --backup=t -rl "{}" "./$COMMON_PREVIEWS" \; #-exec rm -rf "./$d" + + # cleanup filenames... (HACK) + # image.jpg -> image_3.jpg + # image.jpg.~3~ -> image_2.jpg + # image.jpg.~2~ -> image_1.jpg + # image.jpg.~1~ -> image.jpg + # + i=0 + while true ; do + i=$((i + 1)) + images=("$COMMON_PREVIEWS/preview (RAW)/"*.~$i~) + + # break if no matches... + if ! [ -e "${images[0]}" ] ; then + break + fi + + for img in "${images[@]}" ; do + # decrement... + # image.jpg.~(N)~ -> image_(N-1).jpg + mv "$img" "${img/.jpg.~${i}~/_$((i-1)).jpg}" + + # next image does not exist... + # image.jpg -> image_(N).jpg + # image_0.jpg -> image.jpg + if ! [ -e "${img/.jpg.~${i}~/.jpg.~$((i+1))~}" ] ; then + mv "${img/.jpg.~${i}~/.jpg}" "${img/.jpg.~${i}~/_$((i)).jpg}" + mv "${img/.jpg.~${i}~/_0.jpg}" "${img/.jpg.~${i}~/.jpg}" + fi + done + done fi