mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add optional checkGzip parameter to fileName::type(..) method
- this simplifies use of a unified test for directory or file.
fileName::Type what = myfile.type(true, true);
if (what == FILE) ...
if (what == DIRECTORY) ...
- Use distinct bit values for fileName::Type, for possible use in
the future.
- related to issue #1121, since we need a more flexible way of
expanding file or directory.
An alternative would be to add checkGzip to Foam::exists() and
Foam::type() functions, but that would make the code there more
confusing and in the fileHandler classes.
This commit is contained in:
@ -201,9 +201,21 @@ Foam::fileName::fileName(std::initializer_list<word> list)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::fileName::Type Foam::fileName::type(const bool followLink) const
|
Foam::fileName::Type Foam::fileName::type
|
||||||
|
(
|
||||||
|
bool followLink,
|
||||||
|
bool checkGzip
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
return ::Foam::type(*this, followLink);
|
Type t = ::Foam::type(*this, followLink);
|
||||||
|
|
||||||
|
if (checkGzip && (Type::UNDEFINED == t) && size())
|
||||||
|
{
|
||||||
|
// Also check for gzip file?
|
||||||
|
t = ::Foam::type(*this + ".gz", followLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -80,13 +80,13 @@ class fileName
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Enumerations to handle file types and modes.
|
//- Enumerations to handle directory entry types.
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
UNDEFINED, //!< Undefined file type.
|
UNDEFINED = 0, //!< Undefined type
|
||||||
FILE, //!< A file
|
FILE = 1, //!< A file
|
||||||
DIRECTORY, //!< A directory
|
DIRECTORY = 2, //!< A directory
|
||||||
LINK //!< A symlink
|
LINK = 4 //!< A symlink
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -201,9 +201,13 @@ public:
|
|||||||
|
|
||||||
// Interrogation
|
// Interrogation
|
||||||
|
|
||||||
//- Return the file type: FILE, DIRECTORY, LINK or UNDEFINED.
|
//- Return the directory entry type:
|
||||||
// LINK is only returned if followLink=false
|
//- UNDEFINED, FILE, DIRECTORY (or LINK).
|
||||||
Type type(const bool followLink = true) const;
|
//
|
||||||
|
// \param followLink when false it will return LINK for a symlink
|
||||||
|
// rather than following it.
|
||||||
|
// \param checkGzip add an additional test for a gzip FILE
|
||||||
|
Type type(bool followLink=true, bool checkGzip=false) const;
|
||||||
|
|
||||||
//- Return true if string starts with a '/'
|
//- Return true if string starts with a '/'
|
||||||
inline static bool isAbsolute(const std::string& str);
|
inline static bool isAbsolute(const std::string& str);
|
||||||
|
|||||||
Reference in New Issue
Block a user