ENH: more stringent checks for fileName concatenation

- avoids some doubled slashes

STYLE: simplify concatenation of processor directory names
This commit is contained in:
Mark Olesen
2018-10-11 10:07:11 +02:00
parent a77ab5d4eb
commit c4542294a8
11 changed files with 38 additions and 31 deletions

View File

@ -358,8 +358,7 @@ int main(int argc, char *argv[])
if (Pstream::parRun()) if (Pstream::parRun())
{ {
sourceCaseDir = sourceCaseDir =
sourceCaseDir sourceCaseDir/("processor" + Foam::name(Pstream::myProcNo()));
/"processor" + Foam::name(Pstream::myProcNo());
} }
wordList sourcePatches; wordList sourcePatches;
dict.readEntry("sourcePatches", sourcePatches); dict.readEntry("sourcePatches", sourcePatches);

View File

@ -589,7 +589,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci)) args.caseName()/("processor" + Foam::name(proci))
); );
processorDb.setTime(runTime); processorDb.setTime(runTime);
@ -1016,7 +1016,7 @@ int main(int argc, char *argv[])
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName() args.caseName()
/fileName(word("processor") + name(proci)) / ("processor" + Foam::name(proci))
) )
); );
} }
@ -1374,8 +1374,8 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName()/ args.caseName()
fileName(word("processor") + name(procI)) / ("processor" + Foam::name(procI))
); );
processorDb.setTime(runTime); processorDb.setTime(runTime);

View File

@ -305,7 +305,7 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
fileName processorCasePath fileName processorCasePath
( (
time().caseName()/fileName(word("processor") + Foam::name(proci)) time().caseName()/("processor" + Foam::name(proci))
); );
// create a database // create a database

View File

@ -50,7 +50,7 @@ void Foam::faMeshDecomposition::distributeFaces()
( (
Time::controlDictName, Time::controlDictName,
time().rootPath(), time().rootPath(),
time().caseName()/fileName(word("processor") + Foam::name(procI)) time().caseName()/("processor" + Foam::name(procI))
); );
fvMesh procMesh fvMesh procMesh
@ -250,7 +250,7 @@ void Foam::faMeshDecomposition::decomposeMesh()
( (
Time::controlDictName, Time::controlDictName,
time().rootPath(), time().rootPath(),
time().caseName()/fileName(word("processor") + Foam::name(procI)) time().caseName()/("processor" + Foam::name(procI))
); );
fvMesh procFvMesh fvMesh procFvMesh
@ -1059,8 +1059,7 @@ void Foam::faMeshDecomposition::decomposeMesh()
{ {
fileName processorCasePath fileName processorCasePath
( (
time().caseName()/fileName(word("processor") time().caseName()/("processor" + Foam::name(procI))
+ Foam::name(procI))
); );
// create a database // create a database
@ -1179,7 +1178,7 @@ bool Foam::faMeshDecomposition::writeDecomposition()
fileName processorCasePath fileName processorCasePath
( (
time().caseName()/fileName(word("processor") + Foam::name(procI)) time().caseName()/("processor" + Foam::name(procI))
); );
// create a database // create a database

View File

@ -223,7 +223,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci)) args.caseName()/("processor" + Foam::name(proci))
) )
); );
} }

View File

@ -550,7 +550,7 @@ int main(int argc, char *argv[])
forAll(databases, proci) forAll(databases, proci)
{ {
Info<< "Reading database " Info<< "Reading database "
<< args.caseName()/fileName(word("processor") + name(proci)) << args.caseName()/("processor" + Foam::name(proci))
<< endl; << endl;
databases.set databases.set
@ -560,7 +560,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci)) args.caseName()/("processor" + Foam::name(proci))
) )
); );
} }

View File

@ -88,7 +88,7 @@ int main(int argc, char *argv[])
const label nProcs = fileHandler().nProcs(args.path()); const label nProcs = fileHandler().nProcs(args.path());
#else #else
label nProcs = 0; label nProcs = 0;
while (isDir(args.path()/(word("processor") + name(nProcs)))) while (isDir(args.path()/("processor" + Foam::name(nProcs))))
{ {
++nProcs; ++nProcs;
} }
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci)) args.caseName()/("processor" + Foam::name(proci))
) )
); );
} }

View File

@ -396,7 +396,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
rootDirSource, rootDirSource,
caseDirSource/fileName(word("processor") + name(proci)) caseDirSource/("processor" + Foam::name(proci))
); );
#include "setTimeIndex.H" #include "setTimeIndex.H"
@ -471,7 +471,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
rootDirTarget, rootDirTarget,
caseDirTarget/fileName(word("processor") + name(proci)) caseDirTarget/("processor" + Foam::name(proci))
); );
fvMesh meshTarget fvMesh meshTarget
@ -536,7 +536,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
rootDirSource, rootDirSource,
caseDirSource/fileName(word("processor") + name(procISource)) caseDirSource/("processor" + Foam::name(procISource))
); );
#include "setTimeIndex.H" #include "setTimeIndex.H"
@ -572,8 +572,7 @@ int main(int argc, char *argv[])
( (
Time::controlDictName, Time::controlDictName,
rootDirTarget, rootDirTarget,
caseDirTarget/fileName(word("processor") caseDirTarget/("processor" + Foam::name(procITarget))
+ name(procITarget))
); );
fvMesh meshTarget fvMesh meshTarget

View File

@ -1317,7 +1317,7 @@ void Foam::argList::parse
isDir isDir
( (
rootPath_/globalCase_ rootPath_/globalCase_
/ "processor" + Foam::name(++nProcDirs) / ("processor" + Foam::name(++nProcDirs))
) )
) )
{} {}

View File

@ -367,8 +367,7 @@ Foam::fileOperations::masterUncollatedFileOperation::localObjectPath
// Uncollated type, e.g. processor1 // Uncollated type, e.g. processor1
const word procName const word procName
( (
"processor" "processor" + Foam::name(Pstream::myProcNo(Pstream::worldComm))
+Foam::name(Pstream::myProcNo(Pstream::worldComm))
); );
return return
processorsPath processorsPath

View File

@ -426,13 +426,17 @@ Foam::fileName& Foam::fileName::operator/=(const string& other)
{ {
// Two non-empty strings: can concatenate // Two non-empty strings: can concatenate
s.append("/"); if (s.back() != '/' && other.front() != '/')
{
s += '/';
}
s.append(other); s.append(other);
} }
} }
else if (other.size()) else if (other.size())
{ {
// Or, if the first string is empty // The first string is empty
s = other; s = other;
} }
@ -449,16 +453,23 @@ Foam::fileName Foam::operator/(const string& a, const string& b)
if (b.size()) if (b.size())
{ {
// Two non-empty strings: can concatenate // Two non-empty strings: can concatenate
return fileName(a + '/' + b);
if (a.back() == '/' || b.front() == '/')
{
return fileName(a + b);
}
else
{
return fileName(a + '/' + b);
}
} }
return a; return a; // The second string was empty
} }
// Or, if the first string is empty
if (b.size()) if (b.size())
{ {
// The first string is empty
return b; return b;
} }