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

@ -2367,7 +2367,7 @@ int main(int argc, char *argv[])
}
if (!isDir(args.rootPath()))
if (!Foam::isDir(args.rootPath()))
{
FatalErrorInFunction
<< ": cannot open root directory " << args.rootPath()
@ -2393,7 +2393,7 @@ int main(int argc, char *argv[])
// want to delay constructing runTime until we've synced all time
// directories...
const fileName procDir(fileHandler().filePath(args.path()));
if (isDir(procDir))
if (Foam::isDir(procDir))
{
if (decompose)
{
@ -2580,7 +2580,7 @@ int main(int argc, char *argv[])
Info<< "Checking for mesh in " << meshPath << nl << endl;
boolList haveMesh(Pstream::nProcs(), false);
haveMesh[Pstream::myProcNo()] = isFile(meshPath);
haveMesh[Pstream::myProcNo()] = Foam::isFile(meshPath);
Pstream::gatherList(haveMesh);
Pstream::scatterList(haveMesh);
Info<< "Per processor mesh availability:" << nl
@ -2888,16 +2888,15 @@ int main(int argc, char *argv[])
selectedLagrangianFields
);
// If there are any "uniform" directories copy them from
// the master processor
// Copy any "uniform" directories from the master processor
if (Pstream::master())
{
fileName uniformDir0 = runTime.timePath()/"uniform";
if (isDir(uniformDir0))
const fileName uniformDir0(runTime.timePath()/"uniform");
if (Foam::isDir(uniformDir0))
{
Info<< "Detected additional non-decomposed files in "
<< uniformDir0 << endl;
cp(uniformDir0, baseRunTime.timePath());
Foam::cp(uniformDir0, baseRunTime.timePath());
}
}
}
@ -2993,7 +2992,7 @@ int main(int argc, char *argv[])
boolList haveMesh(Pstream::nProcs(), false);
haveMesh[Pstream::myProcNo()] = isFile(meshPath);
haveMesh[Pstream::myProcNo()] = Foam::isFile(meshPath);
Pstream::gatherList(haveMesh);
Pstream::scatterList(haveMesh);
Info<< "Per processor mesh availability:" << nl
@ -3130,17 +3129,13 @@ int main(int argc, char *argv[])
);
// Copy any uniform data
const fileName uniformDir("uniform");
if (isDir(baseRunTime.timePath()/uniformDir))
// Copy "uniform" data from the base directory
const fileName uniformDir0(baseRunTime.timePath()/"uniform");
if (Foam::isDir(uniformDir0))
{
Info<< "Detected additional non-decomposed files in "
<< baseRunTime.timePath()/uniformDir << endl;
cp
(
baseRunTime.timePath()/uniformDir,
runTime.timePath()/uniformDir
);
<< uniformDir0 << endl;
Foam::cp(uniformDir0, runTime.timePath());
}
}
}