Commit c2c00b12 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: add backslashes handling, UNC descriptors in fileName (#1008, #1238)

parent f0a68bfa
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -152,12 +152,18 @@ bool Foam::IOobject::fileNameComponents
name = word::validate(path);
}
else if (first == 0)
else if
(
first == 0
#ifdef _WIN32
|| (first == 2 && path[1] == ':') // Eg, d:/path
#endif
)
{
// Absolute path (starts with '/')
// => no local
instance = path.substr(0, last);
instance = path.substr(first, last);
const std::string ending = path.substr(last+1);
nameLen = ending.size(); // The raw length of name
......
......@@ -60,8 +60,20 @@ Foam::fileName Foam::fileName::validate
std::string::size_type len = 0;
auto iter = s.cbegin();
#ifdef _WIN32
// Preserve UNC \\server-name\...
if (s.length() > 2 && s[0] == '\\' && s[1] == '\\')
{
len += 2;
++iter;
++iter;
}
#endif
char prev = 0;
for (auto iter = s.cbegin(); iter != s.cend(); ++iter)
for (/*nil*/; iter != s.cend(); ++iter)
{
char c = *iter;
......@@ -74,6 +86,9 @@ Foam::fileName Foam::fileName::validate
c = '/';
}
// Could explicitly allow space character or rely on
// allowSpaceInFileName via fileName::valid()
if (fileName::valid(c))
{
if (doClean && prev == '/' && c == '/')
......
......@@ -136,7 +136,18 @@ inline bool Foam::fileName::isAbsolute(const std::string& str)
{
return
(
!str.empty() && str[0] == '/'
(!str.empty() && str[0] == '/')
#ifdef _WIN32
||
(
// Eg, d:/path or \\machine/path
(str.length() > 2) &&
(
(str[1] == ':' && str[2] == '/')
|| (str[0] == '\\' && str[1] == '\\')
)
)
#endif
);
}
......
Supports Markdown
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