mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: allow space char in fileName is now configurable (#1008)
- having whitespace in fileName can be somewhat fragile since it means
that the fileName components do not necessarily correspond to a
'Foam::word'. But in many cases it will work provided that spaces
are not present in the final portion of the simulation directory
itself.
InfoSwitches
{
// Allow space character in fileName (use with caution)
allowSpaceInFileName 0;
}
- now use doClean=true as default for fileName::validate(). Was false.
Unlike fileName::clean() this requires no internal string rewrite
since the characters are being copied. Also handle any path
separator transformations (ie, backslash => forward slash) at the
same time. This makes it resemble the std::filesystem a bit more.
This commit is contained in:
committed by
Andrew Heather
parent
54c10e651d
commit
89245fa796
3
applications/test/fileNameOS/Make/files
Normal file
3
applications/test/fileNameOS/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-fileNameOS.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-fileNameOS
|
||||
2
applications/test/fileNameOS/Make/options
Normal file
2
applications/test/fileNameOS/Make/options
Normal file
@ -0,0 +1,2 @@
|
||||
/* EXE_INC = */
|
||||
/* EXE_LIBS = */
|
||||
106
applications/test/fileNameOS/Test-fileNameOS.C
Normal file
106
applications/test/fileNameOS/Test-fileNameOS.C
Normal file
@ -0,0 +1,106 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Application
|
||||
Test-fileNameOS
|
||||
|
||||
Description
|
||||
Test fileName behaviour, potential OS capabilities etc.
|
||||
|
||||
In the distant future could possibly replace parts with C++ filesystem
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "fileName.H"
|
||||
#include "OSspecific.H"
|
||||
#include "Switch.H"
|
||||
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
void testDirname(const std::string& rawInput)
|
||||
{
|
||||
fileName input(fileName::validate(rawInput));
|
||||
|
||||
Info<< nl
|
||||
<< "input: " << rawInput << nl
|
||||
<< "fileName:" << input << nl
|
||||
<< " path:" << input.path()
|
||||
<< " name:\"" << input.name() << '"'
|
||||
<< " ext:\"" << input.ext() << '"'
|
||||
<< " components: " << flatOutput(input.components()) << nl;
|
||||
|
||||
if (rawInput.size() != input.size())
|
||||
{
|
||||
Info<< " This would be Fatal with debug > 1" << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noParallel();
|
||||
argList::addBoolOption("no-space", "allowSpaceInFileName = false");
|
||||
argList::addBoolOption("with-space", "set allowSpaceInFileName = true");
|
||||
|
||||
#include "setRootCase.H"
|
||||
|
||||
if (args.found("with-space"))
|
||||
{
|
||||
fileName::allowSpaceInFileName = true;
|
||||
}
|
||||
|
||||
if (args.found("no-space"))
|
||||
{
|
||||
fileName::allowSpaceInFileName = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Info<<"fileName with spaces? : "
|
||||
<< Switch(bool(fileName::allowSpaceInFileName)) << nl << nl;
|
||||
|
||||
|
||||
{
|
||||
testDirname("/abc");
|
||||
testDirname("/abc/with space/name");
|
||||
testDirname("/abc/with space/more space");
|
||||
}
|
||||
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user