ENH: foamGetDict avoids overwrite of existing files (-force to override)

This commit is contained in:
Mark Olesen
2019-05-27 11:39:00 +02:00
committed by Andrew Heather
parent 5d8e8610c8
commit 8e5e4180d3

View File

@ -45,6 +45,7 @@ options:
-case <dir> Alternative case directory, default is the cwd -case <dir> Alternative case directory, default is the cwd
-ext <ext> File extension -ext <ext> File extension
-cfg Same as '-e cfg' for '.cfg' files -cfg Same as '-e cfg' for '.cfg' files
-f | -force Force overwrite of existing files
-no-ext Files without extension -no-ext Files without extension
-target <dir> Target directory (default: system, or auto-detected) -target <dir> Target directory (default: system, or auto-detected)
-with-api=NUM Alternative api value for searching -with-api=NUM Alternative api value for searching
@ -86,7 +87,7 @@ projectApi="$FOAM_API"
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
searchExt="<any>" searchExt="<any>"
unset targetDir unset targetDir optForce
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -113,6 +114,9 @@ do
-cfg) -cfg)
searchExt="cfg" searchExt="cfg"
;; ;;
-f | -force)
optForce=true
;;
-target) -target)
[ "$#" -ge 2 ] || die "'$1' option requires an argument" [ "$#" -ge 2 ] || die "'$1' option requires an argument"
targetDir="$2" targetDir="$2"
@ -221,12 +225,27 @@ findFiles()
} }
# Slightly dressed up version of 'cp -v' # Slightly dressed up version of 'cp -v' that does not clobber existing files
copyFile() copyFile()
{ {
local targetFile="$2"
[ -d "$2" ] && targetFile="$targetFile/${1##*/}"
echo 1>&2 echo 1>&2
echo "Copying $1 to $2" 1>&2 if [ -f "$targetFile" ]
\cp "$1" "$2" then
if [ "$optForce" = true ]
then
echo "Overwrite $1 to $2" 1>&2
\cp "$1" "$2"
else
echo "Skip copy $1 to $2" 1>&2
fi
else
echo "Copying $1 to $2" 1>&2
\cp "$1" "$2"
fi
echo 1>&2 echo 1>&2
} }