diff --git a/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C b/applications/utilities/mesh/conversion/Optional/ccm26ToFoam/ccm26ToFoam.C index 025709fac89815dbe8d1c1b00474f801aba11d38..47ec7f913746b0c9582f5a286f1217788708b9be 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 7fcf2a586b57d510fc0ca648cd393dc27cc30c34..486041c71457b39787121d453d06c3bc7fa52b98 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 69439764c7052e3a1dbf78d0b24a279dd1d22f7c..815f082ec7dd179b6a1aba308a0c8c1d4c6c6b1a 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 8f49a947665988024e48fe7b9948e5a830b5612c..a5909c398ab77f69b9dcefb1842266d06cac3101 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 02accb32a8d0a420f99f4190a6fc5c7bf22f9cc5..7901a016c3a3eadcc9d12dbc238e153ff2cf13bb 100644 --- a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C +++ b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C @@ -627,7 +627,7 @@ autoPtr<mapPolyMesh> 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 1e102fb0e5053922fbffdc2ff8aa1bee09ff0102..627f2b15b48a26984c4ced5ec54ff1ece41a4b34 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 c22534ecf53e6c6eabc05d84231ed498fc7163f4..3a48a5deda74c71e13ace6dea886cb5b3fa03c35 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 0856ed6f82d2e37a928dd5be96ddb845a14e8339..41c8a43d6dcea882f0d6e4c3c3703d6d11509996 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 537d6c32494b977adea7e6db963b865acd5815ce..01ef15d74e60c8bd81b08b9c8842c2aed9c75d77 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 ee6fa8188829a62f17f717028a6dea4c690abc3b..f243c48ed4ac6508c5647c75e40f6dcc65630be5 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 3174e615e459f2cdb64b78ebec207e0037584390..0a54089b99c56c9411f1d2aa6894bdafb3e5a1ee 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 efeb7922679a909cffb745d4355e80751fb33467..83951b38711880c0d530479ac030fb78faeb40ea 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,16 +159,17 @@ Foam::IFstream& Foam::IFstream::operator()() const { if (!good()) { - if (!isFile(pathname_) && !isFile(pathname_ + ".gz")) + // also checks .gz file + if (isFile(pathname_, true)) { - FatalIOErrorIn("IFstream::operator()", *this) - << "file " << pathname_ << " does not exist" - << exit(FatalIOError); + check("IFstream::operator()"); + FatalIOError.exit(); } else { - check("IFstream::operator()"); - FatalIOError.exit(); + FatalIOErrorIn("IFstream::operator()", *this) + << "file " << pathname_ << " does not exist" + << exit(FatalIOError); } } diff --git a/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C b/src/OpenFOAM/db/IOstreams/Fstreams/OFstream.C index 2b5849d2e7fde4b8870c516974366f7ed6367b88..f65f0eb636a0081061491e592777256f3789e7b0 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 4384a7ea4183b79031033a9952ddd99046419311..47d9ce48301eaaf354eb5cc3029d95bfbfd1920b 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 1b434670b8a4d290d93060bd9b0b398c9e5f1559..5aaf2f6626372148c7d27e7fe0c5779eeb8345a0 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 4e6c2c6423ecfd003293a14254e2b7e9059b7ace..c6faa26073643fadf0281c180a1a7e511504cba4 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 a8312df3f6b0b97848578965f51e0fe67d3494ca..ccb2d3caa440ccbb0500f6122c2358d60f9db008 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 f48c15bb582b4528c26dd340838838ee3cfa40d2..592382ddf05dc9bcc6fa8325a2d4b53bd1630358 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C @@ -302,7 +302,7 @@ void Foam::dxSurfaceWriter<Type>::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 e5962d8a0ca6c3fa6ff3f401812844485de95b9a..38ad998cc5628c0a9b5818afebbd946ab2698dee 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C @@ -63,7 +63,7 @@ void Foam::foamFileSurfaceWriter<Type>::write { fileName surfaceDir(samplePath/timeDir/surfaceName); - if (!exists(surfaceDir)) + if (!isDir(surfaceDir)) { mkDir(surfaceDir); } @@ -84,7 +84,7 @@ void Foam::foamFileSurfaceWriter<Type>::write fileName foamName(pTraits<Type>::typeName); fileName valuesDir(surfaceDir / (foamName + Field<Type>::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 c71cc140bbe022ce5ef87765dec842d4798efd19..301f8e69dbc554d66af8b30119fa702d6af793ab 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -342,7 +342,7 @@ void Foam::rawSurfaceWriter<Type>::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 cdf0927f19f33e874bdf3b38b6c57e23d10cb0ab..c3ef53df858bd3b92b61745c04c32b64bb559c3a 100644 --- a/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/stl/stlSurfaceWriter.C @@ -64,7 +64,7 @@ void Foam::stlSurfaceWriter<Type>::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 79e9ffe10be3ae584f95d1ecf74b013d401d73cc..d2f529588c5180fdef433f5253982430099d9d64 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -309,7 +309,7 @@ void Foam::vtkSurfaceWriter<Type>::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 1bdc059a8000f82bc4684dcffdc2e9d6b6856801..f2a615fe9ff5d35bf86e9bcba3a1980d9e039480 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()));