diff --git a/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C b/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C index 025709fac8..47ec7f9137 100644 --- a/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C +++ b/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C @@ -615,7 +615,7 @@ int main(int argc, char *argv[]) { fileName ccmFile(args.additionalArgs()[0]); - if (!exists(ccmFile)) + if (!isFile(ccmFile)) { FatalErrorIn(args.executable()) << "Cannot read file " << ccmFile diff --git a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C index 7fcf2a586b..486041c714 100644 --- a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C +++ b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C @@ -129,14 +129,14 @@ int main(int argc, char *argv[]) Info<< "Reading .face file for boundary information" << nl << endl; } - if (!exists(nodeFile) || !exists(eleFile)) + if (!isFile(nodeFile) || !isFile(eleFile)) { FatalErrorIn(args.executable()) << "Cannot read " << nodeFile << " or " << eleFile << exit(FatalError); } - if (readFaceFile && !exists(faceFile)) + if (readFaceFile && !isFile(faceFile)) { FatalErrorIn(args.executable()) << "Cannot read " << faceFile << endl diff --git a/applications/utilities/mesh/generation/blockMesh/blockMeshApp.C b/applications/utilities/mesh/generation/blockMesh/blockMeshApp.C index 69439764c7..815f082ec7 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMeshApp.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMeshApp.C @@ -108,7 +108,11 @@ int main(int argc, char *argv[]) ( new IOobject ( - ( dictPath.isDir() ? dictPath/dictName : dictPath ), + ( + isDir(dictPath) + ? dictPath/dictName + : dictPath + ), runTime, IOobject::MUST_READ, IOobject::NO_WRITE, diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index 8f49a94766..a5909c398a 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -746,7 +746,8 @@ int main(int argc, char *argv[]) Pout<< "Reading commands from file " << batchFile << endl; - if (!exists(batchFile)) + // we also cannot handle .gz files + if (!isFile(batchFile, false)) { FatalErrorIn(args.executable()) << "Cannot open file " << batchFile << exit(FatalError); diff --git a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C index 02accb32a8..7901a016c3 100644 --- a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C +++ b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C @@ -627,7 +627,7 @@ autoPtr createRegionMesh Info<< "Testing:" << io.objectPath() << endl; if (!io.headerOk()) - //if (!exists(io.objectPath())) + // if (!exists(io.objectPath())) { Info<< "Writing dummy " << regionName/io.name() << endl; dictionary dummyDict; diff --git a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C index 1e102fb0e5..627f2b15b4 100644 --- a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C +++ b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C @@ -355,7 +355,7 @@ int main(int argc, char *argv[]) while ( - exists + isDir ( args.rootPath() / args.caseName() diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C index c22534ecf5..3a48a5deda 100644 --- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C +++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C @@ -122,7 +122,11 @@ int main(int argc, char *argv[]) ( new IOobject ( - ( dictPath.isDir() ? dictPath/coordinateSystems::typeName : dictPath ), + ( + isDir(dictPath) + ? dictPath/coordinateSystems::typeName + : dictPath + ), runTime, IOobject::MUST_READ, IOobject::NO_WRITE, diff --git a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C index 0856ed6f82..41c8a43d6d 100644 --- a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C +++ b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) new IOobject ( ( - dictPath.isDir() + isDir(dictPath) ? dictPath/coordinateSystems::typeName : dictPath ), diff --git a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C index 537d6c3249..01ef15d74e 100644 --- a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C +++ b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) new IOobject ( ( - dictPath.isDir() + isDir(dictPath) ? dictPath/coordinateSystems::typeName : dictPath ), diff --git a/src/OSspecific/Unix/Unix.C b/src/OSspecific/Unix/Unix.C index ee6fa81888..f243c48ed4 100644 --- a/src/OSspecific/Unix/Unix.C +++ b/src/OSspecific/Unix/Unix.C @@ -488,9 +488,9 @@ bool Foam::isDir(const fileName& name) // Does the file exist -bool Foam::isFile(const fileName& name) +bool Foam::isFile(const fileName& name, const bool checkGzip) { - return S_ISREG(mode(name)) || S_ISREG(mode(name + ".gz")); + return S_ISREG(mode(name)) || (checkGzip && S_ISREG(mode(name + ".gz"))); } @@ -719,19 +719,19 @@ bool Foam::cp(const fileName& src, const fileName& dest) } -// Create a softlink. destFile should not exist. Returns true if successful. -bool Foam::ln(const fileName& src, const fileName& dest) +// Create a softlink. dst should not exist. Returns true if successful. +bool Foam::ln(const fileName& src, const fileName& dst) { if (Unix::debug) { - Info<< "Create softlink from : " << src << " to " << dest + Info<< "Create softlink from : " << src << " to " << dst << endl; } - if (exists(dest)) + if (exists(dst)) { WarningIn("ln(const fileName&, const fileName&)") - << "destination " << dest << " already exists. Not linking." + << "destination " << dst << " already exists. Not linking." << endl; return false; } @@ -743,40 +743,40 @@ bool Foam::ln(const fileName& src, const fileName& dest) return false; } - if (symlink(src.c_str(), dest.c_str()) == 0) + if (symlink(src.c_str(), dst.c_str()) == 0) { return true; } else { WarningIn("ln(const fileName&, const fileName&)") - << "symlink from " << src << " to " << dest << " failed." << endl; + << "symlink from " << src << " to " << dst << " failed." << endl; return false; } } -// Rename srcFile destFile -bool Foam::mv(const fileName& srcFile, const fileName& destFile) +// Rename srcFile dstFile +bool Foam::mv(const fileName& srcFile, const fileName& dstFile) { if (Unix::debug) { - Info<< "Move : " << srcFile << " to " << destFile << endl; + Info<< "Move : " << srcFile << " to " << dstFile << endl; } if ( - (destFile.type() == fileName::DIRECTORY) - && (srcFile.type() != fileName::DIRECTORY) + dstFile.type() == fileName::DIRECTORY + && srcFile.type() != fileName::DIRECTORY ) { - const fileName destName(destFile/srcFile.name()); + const fileName dstName(dstFile/srcFile.name()); - return rename(srcFile.c_str(), destName.c_str()) == 0; + return rename(srcFile.c_str(), dstName.c_str()) == 0; } else { - return rename(srcFile.c_str(), destFile.c_str()) == 0; + return rename(srcFile.c_str(), dstFile.c_str()) == 0; } } diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 3174e615e4..0a54089b99 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -61,7 +61,7 @@ bool Foam::IOobject::IOobject::fileNameComponents name.clear(); // called with directory - if (::Foam::isDir(path)) + if (!isDir(path)) { WarningIn("IOobject::fileNameComponents(const fileName&, ...)") << " called with directory: " << path << "\n"; diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C index efeb792267..83951b3871 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/IFstream.C @@ -54,7 +54,7 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname) ifPtr_ = new ifstream(pathname.c_str()); // If the file is compressed, decompress it before reading. - if (!ifPtr_->good() && isFile(pathname + ".gz")) + if (!ifPtr_->good() && isFile(pathname + ".gz", false)) { if (IFstream::debug) { @@ -120,8 +120,8 @@ Foam::IFstream::IFstream if (debug) { Info<< "IFstream::IFstream(const fileName&," - "streamFormat format=ASCII," - "versionNumber version=currentVersion) : " + "streamFormat=ASCII," + "versionNumber=currentVersion) : " "could not open file for input" << endl << info() << endl; } @@ -159,17 +159,18 @@ Foam::IFstream& Foam::IFstream::operator()() const { if (!good()) { - if (!isFile(pathname_) && !isFile(pathname_ + ".gz")) + // also checks .gz file + if (isFile(pathname_, true)) + { + check("IFstream::operator()"); + FatalIOError.exit(); + } + else { FatalIOErrorIn("IFstream::operator()", *this) << "file " << pathname_ << " does not exist" << exit(FatalIOError); } - else - { - check("IFstream::operator()"); - FatalIOError.exit(); - } } return const_cast(*this); diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index 2b5849d2e7..f65f0eb636 100644 --- a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C +++ b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C @@ -57,7 +57,8 @@ Foam::OFstreamAllocator::OFstreamAllocator if (compression == IOstream::COMPRESSED) { - if (isFile(pathname)) + // get identically named uncompressed version out of the way + if (isFile(pathname, false)) { rm(pathname); } @@ -66,7 +67,8 @@ Foam::OFstreamAllocator::OFstreamAllocator } else { - if (isFile(pathname + ".gz")) + // get identically named compressed version out of the way + if (isFile(pathname + ".gz", false)) { rm(pathname + ".gz"); } diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 4384a7ea41..47d9ce4830 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -624,7 +624,7 @@ void Foam::argList::displayDoc(bool source) const docFile = docDirs[dirI]/executable_ + docExts[extI]; docFile.expand(); - if (exists(docFile)) + if (isFile(docFile)) { found = true; break; diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 1b434670b8..5aaf2f6626 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -115,18 +115,19 @@ bool chmod(const fileName&, const mode_t); //- Return the file mode mode_t mode(const fileName&); -//- Return the file type: FILE or DIRECTORY +//- Return the file type: DIRECTORY or FILE fileName::Type type(const fileName&); -//- Does the name exist in the file system? +//- Does the name exist (as DIRECTORY or FILE) in the file system? bool exists(const fileName&); -//- Does the name exist as a FILE in the file system? -bool isFile(const fileName&); - //- Does the name exist as a DIRECTORY in the file system? bool isDir(const fileName&); +//- Does the name exist as a FILE in the file system? +// Optionally enable/disable check for gzip file. +bool isFile(const fileName&, const bool checkGzip=true); + //- Return size of file off_t fileSize(const fileName&); diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 4e6c2c6423..c6faa26073 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -55,24 +55,6 @@ Foam::fileName::Type Foam::fileName::type() const } -bool Foam::fileName::exists() const -{ - return ::Foam::exists(*this); -} - - -bool Foam::fileName::isDir() const -{ - return ::Foam::isDir(*this); -} - - -bool Foam::fileName::isFile() const -{ - return ::Foam::isFile(*this); -} - - // Return file name (part beyond last /) // // behaviour compared to /usr/bin/basename: diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index a8312df3f6..ccb2d3caa4 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -134,15 +134,6 @@ public: //- Return the file type: FILE, DIRECTORY or UNDEFINED Type type() const; - //- Does it exist (as FILE or DIRECTORY) in the file system? - bool exists() const; - - //- Does it exist as DIRECTORY in the file system? - bool isDir() const; - - //- Does it exist as FILE in the file system? - bool isFile() const; - // Decomposition //- Return file name (part beyond last /) diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C index f48c15bb58..592382ddf0 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C @@ -302,7 +302,7 @@ void Foam::dxSurfaceWriter::write { fileName surfaceDir(samplePath/timeDir); - if (!exists(surfaceDir)) + if (!isDir(surfaceDir)) { mkDir(surfaceDir); } diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C index e5962d8a0c..38ad998cc5 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C @@ -63,7 +63,7 @@ void Foam::foamFileSurfaceWriter::write { fileName surfaceDir(samplePath/timeDir/surfaceName); - if (!exists(surfaceDir)) + if (!isDir(surfaceDir)) { mkDir(surfaceDir); } @@ -84,7 +84,7 @@ void Foam::foamFileSurfaceWriter::write fileName foamName(pTraits::typeName); fileName valuesDir(surfaceDir / (foamName + Field::typeName)); - if (!exists(valuesDir)) + if (!isDir(valuesDir)) { mkDir(valuesDir); } diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C index c71cc140bb..301f8e69db 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -342,7 +342,7 @@ void Foam::rawSurfaceWriter::write { fileName surfaceDir(samplePath/timeDir); - if (!exists(surfaceDir)) + if (!isDir(surfaceDir)) { mkDir(surfaceDir); } diff --git a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C b/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C index cdf0927f19..c3ef53df85 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C @@ -64,7 +64,7 @@ void Foam::stlSurfaceWriter::write { fileName surfaceDir(samplePath/timeDir); - if (!exists(surfaceDir)) + if (!isDir(surfaceDir)) { mkDir(surfaceDir); } diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C index 79e9ffe10b..d2f529588c 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -309,7 +309,7 @@ void Foam::vtkSurfaceWriter::write { fileName surfaceDir(samplePath/timeDir); - if (!exists(surfaceDir)) + if (!isDir(surfaceDir)) { mkDir(surfaceDir); } diff --git a/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C b/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C index 1bdc059a80..f2a615fe9f 100644 --- a/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C +++ b/src/triSurface/triSurface/interfaces/STL/readSTLBINARY.C @@ -47,8 +47,9 @@ bool triSurface::readSTLBINARY(const fileName& STLfileName) ( new ifstream(STLfileName.c_str(), std::ios::binary) ); + // If the file is compressed, decompress it before reading. - if (!STLfilePtr->good() && isFile(STLfileName + ".gz")) + if (!STLfilePtr->good() && isFile(STLfileName + ".gz", false)) { compressed = true; STLfilePtr.reset(new igzstream((STLfileName + ".gz").c_str()));