From 3d95f56589ad425a3ecc76c856bad70aaa1489a8 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 13 Dec 2018 09:40:54 +0100 Subject: [PATCH] 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. --- .../primitives/strings/fileName/fileName.C | 16 +++++++++++++-- .../primitives/strings/fileName/fileName.H | 20 +++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index e1e6a5ba309..58fe305d3b3 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -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; } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index e34e8a49c14..0f7354d3ff9 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -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); -- GitLab