/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ 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 .
\*---------------------------------------------------------------------------*/
#include "fileStat.H"
#include "IOstreams.H"
#include "timer.H"
#include
#include
#include
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::fileStat::nVariants_ = 2;
const char* Foam::fileStat::variantExts_[] = {"gz", "orig"};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileStat::fileStat()
:
isValid_(false)
{}
Foam::fileStat::fileStat
(
const fileName& fName,
const bool checkVariants,
const bool followLink,
const unsigned int maxTime
)
{
// Work on volatile
volatile bool locIsValid = false;
timer myTimer(maxTime);
if (!timedOut(myTimer))
{
int (*getFileStatus)(const char *, struct stat *) =
followLink ? ::stat : ::lstat;
if (getFileStatus(fName.c_str(), &status_) == 0)
{
locIsValid = true;
}
else if (checkVariants)
{
for (label i = 0; !locIsValid && i < nVariants_; ++ i)
{
const fileName fNameVar = fName + "." + variantExts_[i];
if (getFileStatus(fNameVar.c_str(), &status_) == 0)
{
locIsValid = true;
}
}
}
}
// Copy into (non-volatile, possible register based) member var
isValid_ = locIsValid;
}
Foam::fileStat::fileStat(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileStat::sameDevice(const fileStat& stat2) const
{
return
isValid_
&& (
major(status_.st_dev) == major(stat2.status().st_dev)
&& minor(status_.st_dev) == minor(stat2.status().st_dev)
);
}
bool Foam::fileStat::sameINode(const fileStat& stat2) const
{
return isValid_ && (status_.st_ino == stat2.status().st_ino);
}
bool Foam::fileStat::sameINode(const label iNode) const
{
return isValid_ && (status_.st_ino == ino_t(iNode));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, fileStat& fStat)
{
FixedList