From 14b3f870d81a5c2eb200da0803f4eadde8ea9797 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 19 Mar 2013 21:51:01 +0100 Subject: [PATCH] sanitize filenames --- atom | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/atom b/atom index 78bedb8..fb04af6 100755 --- a/atom +++ b/atom @@ -1047,18 +1047,48 @@ copyFile() { progressSpin } +sanitizeFile() { + string="$1" + # Filenames can't contain / + string="${strings//\// }" + if (( ${destinationfat32compat[$destination]} )) + then + # Filenames can't contain: + string=${string//\?/ } + string=${string//\\/ } + string=${string/// } + string=${string//:/ } + string=${string//\*/ } + string=${string//|/ } + string=${string//\"/ } + + # Filenames can't begin or end with ' ' + string=${string/#+( )/} + string=${string//+( )./.} + string=${string//.+( )/.} + fi + echo "$string" +} + getDestDir() { destdir="${destinationpath[$destination]}/" if [ -n "${destinationrenamepath[$destination]}" ] then destdir+="${destinationrenamepath[$destination]//%\{album\}/$album}" - destdir="${destdir//%\{albumartist\}/$albumartist}" - destdir="${destdir//%\{artist\}/$artist}" - destdir="${destdir//%\{genre\}/$genre}" - destdir="${destdir//%\{title\}/$title}" + replace=$(sanitizeFile "$albumartist") + destdir="${destdir//%\{albumartist\}/$replace}" + replace=$(sanitizeFile "$artist") + destdir="${destdir//%\{artist\}/$replace}" + replace=$(sanitizeFile "$genre") + destdir="${destdir//%\{genre\}/$replace}" + replace=$(sanitizeFile "$title") + destdir="${destdir//%\{title\}/$replace}" tracknumber="${track%/*}" - destdir="${destdir//%\{track\}/$tracknumber}" - destdir="${destdir//%\{year\}/$year}" + replace=$(sanitizeFile "$tracknumber") + destdir="${destdir//%\{track\}/$replace}" + replace=$(sanitizeFile "$year") + destdir="${destdir//%\{year\}/$replace}" else destdir+="${filename%/*}" fi @@ -1083,6 +1113,7 @@ getDestFile() { destfile="${filename##*/}" destfile="${destfile%.*}" fi + destfile=$(sanitizeFile "$destfile") } encodeFile::mp3() {