From 628e5db3f7c0e706e2c6eb1ecc5e75bb2db0b266 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 2 Apr 2013 00:02:42 +0200 Subject: [PATCH] sanitize path --- atom | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/atom b/atom index 7620990..caed8a0 100755 --- a/atom +++ b/atom @@ -1089,6 +1089,7 @@ copyFile() { } sanitizeFile() { + shopt -s extglob string="$1" # Filenames can't contain / string="${string//\// }" @@ -1106,6 +1107,7 @@ sanitizeFile() { # Filenames can't begin or end with ' ' string=${string/#+( )/} + string=${string/%+( )/} string=${string//+( )./.} string=${string//.+( )/.} fi @@ -1133,7 +1135,14 @@ getDestDir() { replace=$(sanitizeFile "$disc") destdir="${destdir//%\{disc\}/$replace}" else - destdir+="${filename%/*}" + destdir+=(sanitizeFile "${filename%%/*}") + part="${filename#*/}/" + while : + do + destdir+="/$(sanitizeFile "${part%%/*}")" + part=${part#*/} + [ -z "$part" ] && break + done fi if ! [ -d "$destdir" ] then