mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: deprecate domainName and full hostName (#2280)
- unused in regular OpenFOAM code - POSIX version uses deprecated gethostbyname() - Windows version never worked COMP: localize, noexcept on internal OSspecific methods STYLE: support fileName::Type SYMLINK and LINK as synonyms
This commit is contained in:
@ -633,10 +633,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
fileName::Type lnAType = lnA.type(false);
|
||||
|
||||
if (lnAType != fileName::LINK)
|
||||
if (lnAType != fileName::SYMLINK)
|
||||
{
|
||||
FatalErrorIn("Test-fileName") << "Type of softlink " << lnA
|
||||
<< " should be " << fileName::LINK
|
||||
<< " should be " << fileName::SYMLINK
|
||||
<< " but is " << lnAType << exit(FatalError);
|
||||
}
|
||||
|
||||
@ -655,10 +655,10 @@ int main(int argc, char *argv[])
|
||||
<< endl;
|
||||
|
||||
Foam::cp(lnA, lnB, false);
|
||||
if (lnB.type(false) != fileName::LINK)
|
||||
if (lnB.type(false) != fileName::SYMLINK)
|
||||
{
|
||||
FatalErrorIn("Test-fileName") << "Type of softlink " << lnB
|
||||
<< " should be " << fileName::LINK
|
||||
<< " should be " << fileName::SYMLINK
|
||||
<< " but is " << lnB.type(false) << exit(FatalError);
|
||||
}
|
||||
if (lnB.type(true) != fileName::DIRECTORY)
|
||||
|
||||
@ -459,7 +459,7 @@ bool Foam::removeEmptyDir(const fileName& path)
|
||||
Foam::readDir
|
||||
(
|
||||
path,
|
||||
fileName::LINK,
|
||||
fileName::SYMLINK,
|
||||
false, // filterGz
|
||||
false // followLink
|
||||
)
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2011 Symscape
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -83,7 +83,7 @@ namespace Foam
|
||||
|
||||
|
||||
// Move file, overwriting existing
|
||||
static bool renameFile(const fileName& src, const fileName& dst)
|
||||
static bool renameFile(const std::string& src, const std::string& dst)
|
||||
{
|
||||
constexpr const int flags
|
||||
(
|
||||
@ -132,7 +132,7 @@ class directoryIterator
|
||||
public:
|
||||
|
||||
//- Construct for dirName, optionally allowing hidden files/dirs
|
||||
directoryIterator(const fileName& dirName, bool allowHidden = false)
|
||||
directoryIterator(const std::string& dirName, bool allowHidden = false)
|
||||
:
|
||||
handle_(INVALID_HANDLE_VALUE),
|
||||
exists_(false),
|
||||
@ -170,13 +170,13 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Directory existed for opening
|
||||
bool exists() const
|
||||
bool exists() const noexcept
|
||||
{
|
||||
return exists_;
|
||||
}
|
||||
|
||||
//- Directory pointer is valid
|
||||
bool good() const
|
||||
bool good() const noexcept
|
||||
{
|
||||
return (INVALID_HANDLE_VALUE != handle_);
|
||||
}
|
||||
@ -192,7 +192,7 @@ public:
|
||||
}
|
||||
|
||||
//- The current item
|
||||
const std::string& val() const
|
||||
const std::string& val() const noexcept
|
||||
{
|
||||
return item_;
|
||||
}
|
||||
@ -225,13 +225,13 @@ public:
|
||||
// Member Operators
|
||||
|
||||
//- Same as good()
|
||||
operator bool() const
|
||||
operator bool() const noexcept
|
||||
{
|
||||
return good();
|
||||
}
|
||||
|
||||
//- Same as val()
|
||||
const std::string& operator*() const
|
||||
const std::string& operator*() const noexcept
|
||||
{
|
||||
return val();
|
||||
}
|
||||
@ -407,7 +407,7 @@ bool Foam::setEnv
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::hostName(bool)
|
||||
Foam::string Foam::hostName()
|
||||
{
|
||||
const DWORD bufLen = MAX_COMPUTERNAME_LENGTH + 1;
|
||||
TCHAR buf[bufLen];
|
||||
@ -417,12 +417,20 @@ Foam::string Foam::hostName(bool)
|
||||
}
|
||||
|
||||
|
||||
// DEPRECATED (2022-01)
|
||||
Foam::string Foam::hostName(bool)
|
||||
{
|
||||
return Foam::hostName();
|
||||
}
|
||||
|
||||
|
||||
// DEPRECATED (2022-01)
|
||||
Foam::string Foam::domainName()
|
||||
{
|
||||
// Could use ::gethostname and ::gethostbyname like POSIX.C, but would
|
||||
// then need to link against ws_32. Prefer to minimize dependencies.
|
||||
|
||||
return string::null;
|
||||
return string();
|
||||
}
|
||||
|
||||
|
||||
@ -452,7 +460,7 @@ Foam::fileName Foam::home()
|
||||
|
||||
if (env.empty())
|
||||
{
|
||||
env = Foam::getEnv("USERPROFILE");
|
||||
env = Foam::getEnv("USERPROFILE");
|
||||
}
|
||||
|
||||
return env;
|
||||
@ -595,21 +603,21 @@ Foam::fileName::Type Foam::type
|
||||
// Ignore an empty name => always UNDEFINED
|
||||
if (name.empty())
|
||||
{
|
||||
return fileName::UNDEFINED;
|
||||
return fileName::Type::UNDEFINED;
|
||||
}
|
||||
|
||||
const DWORD m = ::GetFileAttributes(name.c_str());
|
||||
|
||||
if (ms_isreg(m))
|
||||
{
|
||||
return fileName::FILE;
|
||||
return fileName::Type::FILE;
|
||||
}
|
||||
else if (ms_isdir(m))
|
||||
{
|
||||
return fileName::DIRECTORY;
|
||||
return fileName::Type::DIRECTORY;
|
||||
}
|
||||
|
||||
return fileName::UNDEFINED;
|
||||
return fileName::Type::UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,8 +35,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef MSwindows_H
|
||||
#define MSwindows_H
|
||||
#ifndef Foam_MSwindows_H
|
||||
#define Foam_MSwindows_H
|
||||
|
||||
#include "className.H"
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -142,7 +142,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct for dirName, optionally allowing hidden files/dirs
|
||||
directoryIterator(const fileName& dirName, bool allowHidden = false)
|
||||
directoryIterator(const std::string& dirName, bool allowHidden = false)
|
||||
:
|
||||
dirptr_(nullptr),
|
||||
exists_(false),
|
||||
@ -168,13 +168,13 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- Directory open succeeded
|
||||
bool exists() const
|
||||
bool exists() const noexcept
|
||||
{
|
||||
return exists_;
|
||||
}
|
||||
|
||||
//- Directory pointer is valid
|
||||
bool good() const
|
||||
bool good() const noexcept
|
||||
{
|
||||
return dirptr_;
|
||||
}
|
||||
@ -190,7 +190,7 @@ public:
|
||||
}
|
||||
|
||||
//- The current item
|
||||
const std::string& val() const
|
||||
const std::string& val() const noexcept
|
||||
{
|
||||
return item_;
|
||||
}
|
||||
@ -220,13 +220,13 @@ public:
|
||||
// Member Operators
|
||||
|
||||
//- Same as good()
|
||||
operator bool() const
|
||||
operator bool() const noexcept
|
||||
{
|
||||
return good();
|
||||
}
|
||||
|
||||
//- Same as val()
|
||||
const std::string& operator*() const
|
||||
const std::string& operator*() const noexcept
|
||||
{
|
||||
return val();
|
||||
}
|
||||
@ -302,25 +302,36 @@ bool Foam::setEnv
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::hostName(bool full)
|
||||
Foam::string Foam::hostName()
|
||||
{
|
||||
char buf[128];
|
||||
::gethostname(buf, sizeof(buf));
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
// DEPRECATED (2022-01)
|
||||
Foam::string Foam::hostName(bool full)
|
||||
{
|
||||
// implementation as per hostname from net-tools
|
||||
if (full)
|
||||
{
|
||||
char buf[128];
|
||||
::gethostname(buf, sizeof(buf));
|
||||
|
||||
struct hostent *hp = ::gethostbyname(buf);
|
||||
if (hp)
|
||||
{
|
||||
return hp->h_name;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
return buf;
|
||||
return Foam::hostName();
|
||||
}
|
||||
|
||||
|
||||
// DEPRECATED (2022-01)
|
||||
Foam::string Foam::domainName()
|
||||
{
|
||||
char buf[128];
|
||||
@ -338,7 +349,7 @@ Foam::string Foam::domainName()
|
||||
}
|
||||
}
|
||||
|
||||
return string::null;
|
||||
return string();
|
||||
}
|
||||
|
||||
|
||||
@ -713,12 +724,16 @@ mode_t Foam::mode(const fileName& name, const bool followLink)
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName::Type Foam::type(const fileName& name, const bool followLink)
|
||||
Foam::fileName::Type Foam::type
|
||||
(
|
||||
const fileName& name,
|
||||
const bool followLink
|
||||
)
|
||||
{
|
||||
// Ignore an empty name => always UNDEFINED
|
||||
if (name.empty())
|
||||
{
|
||||
return fileName::UNDEFINED;
|
||||
return fileName::Type::UNDEFINED;
|
||||
}
|
||||
|
||||
if (POSIX::debug)
|
||||
@ -730,18 +745,18 @@ Foam::fileName::Type Foam::type(const fileName& name, const bool followLink)
|
||||
|
||||
if (S_ISREG(m))
|
||||
{
|
||||
return fileName::FILE;
|
||||
return fileName::Type::FILE;
|
||||
}
|
||||
else if (S_ISLNK(m))
|
||||
{
|
||||
return fileName::LINK;
|
||||
return fileName::Type::SYMLINK;
|
||||
}
|
||||
else if (S_ISDIR(m))
|
||||
{
|
||||
return fileName::DIRECTORY;
|
||||
return fileName::Type::DIRECTORY;
|
||||
}
|
||||
|
||||
return fileName::UNDEFINED;
|
||||
return fileName::Type::UNDEFINED;
|
||||
}
|
||||
|
||||
|
||||
@ -1033,7 +1048,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (srcType == fileName::LINK)
|
||||
else if (srcType == fileName::SYMLINK)
|
||||
{
|
||||
// If dest is a directory, create the destination file name.
|
||||
if (destFile.type() == fileName::DIRECTORY)
|
||||
|
||||
@ -34,8 +34,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef POSIX_H
|
||||
#define POSIX_H
|
||||
#ifndef Foam_POSIX_H
|
||||
#define Foam_POSIX_H
|
||||
|
||||
#include "className.H"
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ namespace Foam
|
||||
|
||||
const fileName::Type pathType = Foam::type(otherName, false);
|
||||
|
||||
if (pathType == fileName::FILE || pathType == fileName::LINK)
|
||||
if (pathType == fileName::FILE || pathType == fileName::SYMLINK)
|
||||
{
|
||||
Foam::rm(otherName);
|
||||
}
|
||||
@ -60,7 +60,7 @@ namespace Foam
|
||||
// Disallow writing into symlinked files.
|
||||
// Eg, avoid problems with symlinked initial fields
|
||||
|
||||
if (!append && Foam::type(targetName, false) == fileName::LINK)
|
||||
if (!append && Foam::type(targetName, false) == fileName::SYMLINK)
|
||||
{
|
||||
Foam::rm(targetName);
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ static inline bool accept
|
||||
)
|
||||
{
|
||||
// followLink(true), checkGzip(true)
|
||||
// -> returns (UNDEFINED | FILE | DIRECTORY), no need to check for (LINK)
|
||||
// -> returns (UNDEFINED | FILE | DIRECTORY), no need to check for (SYMLINK)
|
||||
const auto t = name.type(true, true);
|
||||
|
||||
return
|
||||
|
||||
@ -38,8 +38,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fileOperation_H
|
||||
#define fileOperation_H
|
||||
#ifndef Foam_fileOperation_H
|
||||
#define Foam_fileOperation_H
|
||||
|
||||
#include "ISstream.H"
|
||||
#include "Ostream.H"
|
||||
@ -262,7 +262,7 @@ public:
|
||||
const bool followLink = true
|
||||
) const = 0;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or LINK
|
||||
//- Return the file type: DIRECTORY, FILE or SYMLINK
|
||||
virtual fileName::Type type
|
||||
(
|
||||
const fileName&,
|
||||
|
||||
@ -59,8 +59,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fileOperations_masterUncollatedFileOperation_H
|
||||
#define fileOperations_masterUncollatedFileOperation_H
|
||||
#ifndef Foam_fileOperations_masterUncollatedFileOperation_H
|
||||
#define Foam_fileOperations_masterUncollatedFileOperation_H
|
||||
|
||||
#include "fileOperation.H"
|
||||
#include "OSspecific.H"
|
||||
@ -515,7 +515,7 @@ public:
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or LINK
|
||||
//- Return the file type: DIRECTORY, FILE or SYMLINK
|
||||
virtual fileName::Type type
|
||||
(
|
||||
const fileName&,
|
||||
|
||||
@ -32,8 +32,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fileOperations_uncollatedFileOperation_H
|
||||
#define fileOperations_uncollatedFileOperation_H
|
||||
#ifndef Foam_fileOperations_uncollatedFileOperation_H
|
||||
#define Foam_fileOperations_uncollatedFileOperation_H
|
||||
|
||||
#include "fileOperation.H"
|
||||
#include "OSspecific.H"
|
||||
@ -110,7 +110,7 @@ public:
|
||||
const bool followLink = true
|
||||
) const;
|
||||
|
||||
//- Return the file type: DIRECTORY, FILE or LINK
|
||||
//- Return the file type: DIRECTORY, FILE or SYMLINK
|
||||
virtual fileName::Type type
|
||||
(
|
||||
const fileName&,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,8 +36,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OSspecific_H
|
||||
#define OSspecific_H
|
||||
#ifndef Foam_OSspecific_H
|
||||
#define Foam_OSspecific_H
|
||||
|
||||
#include "fileNameList.H"
|
||||
#include "stringList.H"
|
||||
@ -82,10 +82,16 @@ FOAM_DEPRECATED_FOR(2020-05, "hasEnv() function")
|
||||
inline bool env(const std::string& envName) { return Foam::hasEnv(envName); }
|
||||
|
||||
//- Return the system's host name, as per hostname(1)
|
||||
// \note the full name (as per the '-f' option) may be unreliable
|
||||
string hostName(bool full=false);
|
||||
string hostName();
|
||||
|
||||
//- Return the system's domain name, as per hostname(1) with the '-d' option
|
||||
//- Deprecated(2022-01) full hostname resolution may be unreliable
|
||||
// \deprecated(2022-01) - use hostname() function without parameter
|
||||
FOAM_DEPRECATED_FOR(2022-01, "hostname() function without parameter")
|
||||
string hostName(bool full);
|
||||
|
||||
//- Deprecated(2022-01) domain name resolution may be unreliable
|
||||
// \deprecated(2022-01) - avoid usage entirely
|
||||
FOAM_DEPRECATED_FOR(2022-01, "nothing : avoid using at all")
|
||||
string domainName();
|
||||
|
||||
//- Return the user's login name
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -45,8 +45,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef fileName_H
|
||||
#define fileName_H
|
||||
#ifndef Foam_fileName_H
|
||||
#define Foam_fileName_H
|
||||
|
||||
#include "word.H"
|
||||
|
||||
@ -81,9 +81,10 @@ public:
|
||||
enum Type
|
||||
{
|
||||
UNDEFINED = 0, //!< Undefined type
|
||||
FILE = 1, //!< A file
|
||||
FILE = 1, //!< A regular file
|
||||
DIRECTORY = 2, //!< A directory
|
||||
LINK = 4 //!< A symlink
|
||||
SYMLINK = 4, //!< A symbolic link
|
||||
LINK = SYMLINK //!< Same as symlink
|
||||
};
|
||||
|
||||
|
||||
@ -225,9 +226,9 @@ public:
|
||||
// Interrogation
|
||||
|
||||
//- Return the directory entry type:
|
||||
//- UNDEFINED, FILE, DIRECTORY (or LINK).
|
||||
//- UNDEFINED, FILE, DIRECTORY (or SYMLINK).
|
||||
//
|
||||
// \param followLink when false it will return LINK for a symlink
|
||||
// \param followLink when false it will return SYMLINK 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;
|
||||
|
||||
Reference in New Issue
Block a user