diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 0574decef1b34295f20337c783f1a0d8ba28444c..14c3eba99ec834382a43b72ff97accba63107709 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -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 diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index f74c6877a68a228370cb217950d370e31cf4248d..d0af6d8869f018ab892242185dfa706b1734eb8f 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -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 == '/') diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H index 2eefa95f72b4e782e744c78f978b9d28a5b8df68..4aa86b87d4c156c49cf9ee1d7a0e445a8655646e 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H @@ -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 ); }