BUG: Foam::cp inadvertently creates recursive directories (fixes #2235)

- noticed by Robin Knowles with `decomposePar -fields -copyZero`

  The internals for the Foam:cp method combine the behaviour of
  a regular `cp` and `cp -R` combined.

  When source and target are both directories, the old implementation
  created a subdirectory for the contents.
  This normally fine,

      ok:  cp "path1/0/" to "path2/1" -> "path2/1/2"
      BUT: cp "path1/0/" to "path2/0" -> "path2/0/0" !!

  Now add check for the basenames first.
  If they are identical, we probably meant to copy directory contents
  only, without the additional subdir layer.

BUG: decomposePar -fields -copyZero copies the wrong directory

- was using the current time name (usually latest) instead of copying
  the 0 directory

ENH: accept 0.orig directories as a fallback to copy if the 0 directory
is missing
This commit is contained in:
Mark Olesen
2021-10-15 20:10:53 +02:00
parent 4a0646451d
commit fe8c630936
5 changed files with 85 additions and 49 deletions

View File

@ -64,7 +64,7 @@ int main(int argc, char *argv[])
// Back-up old optimisationDict, to maintain potential comments in it
if (Pstream::master())
{
cp(optDict.objectPath(), optDict.objectPath() + ".org");
Foam::cp(optDict.objectPath(), optDict.objectPath() + ".org");
}
// Construct mesh movement object and grab active design variables