Skip to content
Snippets Groups Projects
Commit 922ea566 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

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
parent cc290b7c
Branches
Tags
No related merge requests found
......@@ -108,28 +108,22 @@ static inline bool isOutsideOfCase(const std::string& file)
// * * * * * * * * * * * * 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
(
const fileName& rawPath,
const fileName& path,
fileName& instance,
fileName& local,
word& name
)
{
// Re-interpret the path as a file-system path.
fileName path(rawPath);
path.toAbsolute();
// Convert explicit relative file-system path to absolute file-system path.
if (path.startsWith("./") || path.startsWith("../"))
{
fileName absPath = cwd()/path;
absPath.clean();
return fileNameComponents(absPath, instance, local, name);
}
instance.clear();
local.clear();
......
......@@ -174,15 +174,15 @@ protected:
// Protected Member Functions
//- 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();
//- Construct and return an IFstream for the object given the
// exact file. The results is nullptr if the stream construction failed
Istream* objectStream(const fileName&);
//- Return an IFstream for the object given the exact file.
// \Return nullptr if the stream construction failed
Istream* objectStream(const fileName& fName);
//- Set the object state to bad
void setBad(const string&);
void setBad(const string& s);
public:
......@@ -200,6 +200,20 @@ public:
// Static Member Functions
//- 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
(
const fileName& path,
......@@ -240,9 +254,11 @@ public:
);
//- Construct from path, registry, io options.
// Uses fileNameComponents() to split path into components. The
// path argument is regarded as a file system path, not a case-relative
// path. Any './' gets expanded to the current working directory.
// Uses fileNameComponents() to split path into components.
// A path that starts with a '/' is regarded as a file system path.
// 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
(
const fileName& path,
......@@ -300,6 +316,9 @@ public:
//- Return name of the class name read from header
inline const word& headerClassName() const;
//- Return non-constant access to the class name read from header
inline word& headerClassName();
//- Return the optional note
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
{
return note_;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment