mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: IOobject interpretation of ./ in construct-from-fileName (closes #482)
- Resolve ambiguity by using the following rules: 1) starts with '/' => absolute file-system path 2) starts with './' or '../' => file-system path relative to CWD 3) otherwise treat as relative to the case STYLE: allow write access to headerClassName
This commit is contained in:
@ -108,28 +108,22 @@ static inline bool isOutsideOfCase(const std::string& file)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Return components following the IOobject requirements
|
|
||||||
//
|
|
||||||
// behaviour
|
|
||||||
// input IOobject(instance, local, name)
|
|
||||||
// ----- ------
|
|
||||||
// "foo" ("", "", "foo")
|
|
||||||
// "foo/bar" ("foo", "", "bar")
|
|
||||||
// "foo/bar/" ERROR - no name
|
|
||||||
// "foo/xxx/bar" ("foo", "xxx", "bar")
|
|
||||||
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
|
|
||||||
// "/xxx/yyy/bar" ("/xxx/yyy", "", "bar")
|
|
||||||
bool Foam::IOobject::fileNameComponents
|
bool Foam::IOobject::fileNameComponents
|
||||||
(
|
(
|
||||||
const fileName& rawPath,
|
const fileName& path,
|
||||||
fileName& instance,
|
fileName& instance,
|
||||||
fileName& local,
|
fileName& local,
|
||||||
word& name
|
word& name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Re-interpret the path as a file-system path.
|
// Convert explicit relative file-system path to absolute file-system path.
|
||||||
fileName path(rawPath);
|
if (path.startsWith("./") || path.startsWith("../"))
|
||||||
path.toAbsolute();
|
{
|
||||||
|
fileName absPath = cwd()/path;
|
||||||
|
absPath.clean();
|
||||||
|
|
||||||
|
return fileNameComponents(absPath, instance, local, name);
|
||||||
|
}
|
||||||
|
|
||||||
instance.clear();
|
instance.clear();
|
||||||
local.clear();
|
local.clear();
|
||||||
|
|||||||
@ -174,15 +174,15 @@ protected:
|
|||||||
// Protected Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
//- Construct and return an IFstream for the object.
|
//- Construct and return an IFstream for the object.
|
||||||
// The results is nullptr if the stream construction failed
|
// \Return nullptr if the stream construction failed
|
||||||
Istream* objectStream();
|
Istream* objectStream();
|
||||||
|
|
||||||
//- Construct and return an IFstream for the object given the
|
//- Return an IFstream for the object given the exact file.
|
||||||
// exact file. The results is nullptr if the stream construction failed
|
// \Return nullptr if the stream construction failed
|
||||||
Istream* objectStream(const fileName&);
|
Istream* objectStream(const fileName& fName);
|
||||||
|
|
||||||
//- Set the object state to bad
|
//- Set the object state to bad
|
||||||
void setBad(const string&);
|
void setBad(const string& s);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -200,6 +200,20 @@ public:
|
|||||||
// Static Member Functions
|
// Static Member Functions
|
||||||
|
|
||||||
//- Split path into instance, local, name components
|
//- Split path into instance, local, name components
|
||||||
|
//
|
||||||
|
// The splitting behaviour is as follows:
|
||||||
|
// \verbatim
|
||||||
|
// input | instance | local | name
|
||||||
|
// ----------- | ---------- | ----- | ----
|
||||||
|
// a | | | a
|
||||||
|
// a/b | a | | b
|
||||||
|
// a/b/c/d | a | b/c | d
|
||||||
|
// /a/b/c | /a/b | | c
|
||||||
|
// ./a/b/c | PWD/a/b | | c
|
||||||
|
// ../a/b/c | PWD/../a/b | | c
|
||||||
|
// a/b/ | ERROR | |
|
||||||
|
// \endverbatim
|
||||||
|
// where PWD is the Foam::cwd() current working directory
|
||||||
static bool fileNameComponents
|
static bool fileNameComponents
|
||||||
(
|
(
|
||||||
const fileName& path,
|
const fileName& path,
|
||||||
@ -240,9 +254,11 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from path, registry, io options.
|
//- Construct from path, registry, io options.
|
||||||
// Uses fileNameComponents() to split path into components. The
|
// Uses fileNameComponents() to split path into components.
|
||||||
// path argument is regarded as a file system path, not a case-relative
|
// A path that starts with a '/' is regarded as a file system path.
|
||||||
// path. Any './' gets expanded to the current working directory.
|
// Paths starting with either './' or '../' are relative to
|
||||||
|
// current working directory (and replaced with absolute equivalents).
|
||||||
|
// All other paths are considered to be relative to the case.
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
const fileName& path,
|
const fileName& path,
|
||||||
@ -300,6 +316,9 @@ public:
|
|||||||
//- Return name of the class name read from header
|
//- Return name of the class name read from header
|
||||||
inline const word& headerClassName() const;
|
inline const word& headerClassName() const;
|
||||||
|
|
||||||
|
//- Return non-constant access to the class name read from header
|
||||||
|
inline word& headerClassName();
|
||||||
|
|
||||||
//- Return the optional note
|
//- Return the optional note
|
||||||
inline const string& note() const;
|
inline const string& note() const;
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,12 @@ inline const Foam::word& Foam::IOobject::headerClassName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Foam::word& Foam::IOobject::headerClassName()
|
||||||
|
{
|
||||||
|
return headerClassName_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline const Foam::string& Foam::IOobject::note() const
|
inline const Foam::string& Foam::IOobject::note() const
|
||||||
{
|
{
|
||||||
return note_;
|
return note_;
|
||||||
|
|||||||
Reference in New Issue
Block a user