From 8e5e4180d303b75bf04641fe41ba0e935044d830 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 27 May 2019 11:39:00 +0200 Subject: [PATCH] ENH: foamGetDict avoids overwrite of existing files (-force to override) --- bin/foamGetDict | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/bin/foamGetDict b/bin/foamGetDict index 35ded94201d..846cf62ec5f 100755 --- a/bin/foamGetDict +++ b/bin/foamGetDict @@ -45,6 +45,7 @@ options: -case <dir> Alternative case directory, default is the cwd -ext <ext> File extension -cfg Same as '-e cfg' for '.cfg' files + -f | -force Force overwrite of existing files -no-ext Files without extension -target <dir> Target directory (default: system, or auto-detected) -with-api=NUM Alternative api value for searching @@ -86,7 +87,7 @@ projectApi="$FOAM_API" #------------------------------------------------------------------------------- searchExt="<any>" -unset targetDir +unset targetDir optForce while [ "$#" -gt 0 ] do @@ -113,6 +114,9 @@ do -cfg) searchExt="cfg" ;; + -f | -force) + optForce=true + ;; -target) [ "$#" -ge 2 ] || die "'$1' option requires an argument" 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() { + local targetFile="$2" + + [ -d "$2" ] && targetFile="$targetFile/${1##*/}" + echo 1>&2 - echo "Copying $1 to $2" 1>&2 - \cp "$1" "$2" + if [ -f "$targetFile" ] + 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 } -- GitLab