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:
Mark Olesen 2018-12-13 09:40:54 +01:00
parent 38de85cdf8
commit 3d95f56589
2 changed files with 26 additions and 10 deletions

View File

@ -201,9 +201,21 @@ Foam::fileName::fileName(std::initializer_list<word> list)
// * * * * * * * * * * * * * * * 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;
}

View File

@ -80,13 +80,13 @@ class fileName
public:
//- Enumerations to handle file types and modes.
//- Enumerations to handle directory entry types.
enum Type
{
UNDEFINED, //!< Undefined file type.
FILE, //!< A file
DIRECTORY, //!< A directory
LINK //!< A symlink
UNDEFINED = 0, //!< Undefined type
FILE = 1, //!< A file
DIRECTORY = 2, //!< A directory
LINK = 4 //!< A symlink
};
@ -201,9 +201,13 @@ public:
// Interrogation
//- Return the file type: FILE, DIRECTORY, LINK or UNDEFINED.
// LINK is only returned if followLink=false
Type type(const bool followLink = true) const;
//- Return the directory entry type:
//- UNDEFINED, FILE, DIRECTORY (or LINK).
//
// \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 '/'
inline static bool isAbsolute(const std::string& str);