Skip to content

foamCloneCase generates unnecessary folder when no time directories present

Summary

foamCloneCase generates unnecessary folder when no time directories present. For example, if you create a case basic_case with only constant and system directories, the results of cloning such a case with

foamCloneCase basic_case test

will be:

test
├── basic_case  <--- this shouldn't be here
├── constant
│  ├── transportProperties
│  └── turbulenceProperties
└── system
   ├── controlDict
   ├── fvSchemes
   └── fvSolution

Steps to reproduce

  1. Create a case like that:
    basic_case
    ├── constant
    │  ├── transportProperties
    │  └── turbulenceProperties
    └── system
       ├── controlDict
       ├── fvSchemes
       └── fvSolution
  2. Clone with
    foamCloneCase basic_case test

Example case

Attached archive of basic_case example

What is the current bug behaviour?

The shell script gets the path of the time folder to be copied at the line 74:

TIME_DIR="$(foamListTimes -withZero -case $1 | $TIME_OPTION)"

In the presented case TIME_DIR variable will simply be empty which will lead to bad copy operation at line 77

cp -r $1/system $1/constant $1/${TIME_DIR} $2

as $1/${TIME_DIR} will simply evaluate to base_case/ in the presented example, trying to copy the case into itself.

What is the expected correct behavior?

Copy only what is in the original case, without creating any unnecessary folders.

Environment information

  • OpenFOAM version : v2306
  • Operating system : Ubuntu 23.04
  • Hardware info : -
  • Compiler : -

Possible fixes

Test if the variable is empty, only copy if it is. Example solution:

echo "Copying case directories from $1 to $2"
cp -r $1/system $1/constant $2

TIME_DIR="$(foamListTimes -withZero -case $1 | $TIME_OPTION)"
if [ ! -z "$TIME_DIR" ]
then
    cp -r $1/${TIME_DIR} $2
else
    echo "No time directories to copy"
fi

The patch for this solution is attached as well.foamCloneCase.patch