Commit ffd9bb08 authored by Mark Olesen's avatar Mark Olesen
Browse files

OSspecific: altered file tests

- removed the previously added fileName type(), isDir(), isFile() methods.

- added optional bool parameter to isFile() function to explicitly
  enable/disable the check for gzip files.

- fixed minor bugginess where the default usage of isFile() would result in
  false positive matches.

- be slightly more stringent and use isDir() and isFile() instead of
  exists() function when we actually know the expected type.
parent fb29e085
......@@ -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
......
......@@ -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
......
......@@ -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,
......
......@@ -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);
......
......@@ -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;
......
......@@ -355,7 +355,7 @@ int main(int argc, char *argv[])
while
(
exists
isDir
(
args.rootPath()
/ args.caseName()
......
......@@ -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,
......
......@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
new IOobject
(
(
dictPath.isDir()
isDir(dictPath)
? dictPath/coordinateSystems::typeName
: dictPath
),
......
......@@ -133,7 +133,7 @@ int main(int argc, char *argv[])
new IOobject
(
(
dictPath.isDir()
isDir(dictPath)
? dictPath/coordinateSystems::typeName
: dictPath
),
......
......@@ -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;
}
}
......
......@@ -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";
......
......@@ -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);
}
}
......
......@@ -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");
}
......
......@@ -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;
......
......@@ -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&);
......
......@@ -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:
......
......@@ -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 /)
......
......@@ -302,7 +302,7 @@ void Foam::dxSurfaceWriter<Type>::write
{
fileName surfaceDir(samplePath/timeDir);
if (!exists(surfaceDir))
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
......
......@@ -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);
}
......
......@@ -342,7 +342,7 @@ void Foam::rawSurfaceWriter<Type>::write
{
fileName surfaceDir(samplePath/timeDir);
if (!exists(surfaceDir))
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
......
......@@ -64,7 +64,7 @@ void Foam::stlSurfaceWriter<Type>::write
{
fileName surfaceDir(samplePath/timeDir);
if (!exists(surfaceDir))
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
......
......@@ -309,7 +309,7 @@ void Foam::vtkSurfaceWriter<Type>::write
{
fileName surfaceDir(samplePath/timeDir);
if (!exists(surfaceDir))
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
......
......@@ -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()));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment