From 49c7b3770527aa6f8346552a695742b05fbd17c9 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 1 Aug 2016 14:11:05 +0200
Subject: [PATCH] BUG: 'processor' in directory name causes issues (issue #199)

- previously just detected the presence of "processor" in the case
  path name. Restrict to checking the final portion.
  Does not solve all problems, but solves ones like this:

      test-new-processor-generation/....
---
 src/OpenFOAM/db/Time/TimePaths.C | 79 ++++++++++++++++----------------
 src/OpenFOAM/db/Time/TimePaths.H |  8 +++-
 2 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/src/OpenFOAM/db/Time/TimePaths.C b/src/OpenFOAM/db/Time/TimePaths.C
index 14d004e4d46..ae5b5d182f9 100644
--- a/src/OpenFOAM/db/Time/TimePaths.C
+++ b/src/OpenFOAM/db/Time/TimePaths.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -26,6 +26,38 @@ License
 #include "TimePaths.H"
 #include "IOstreams.H"
 
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+bool Foam::TimePaths::detectProcessorCase()
+{
+    if (processorCase_)
+    {
+        return processorCase_;
+    }
+
+    // Look for "processor", but should really check for following digits too
+    const std::string::size_type sep = globalCaseName_.rfind('/');
+    const std::string::size_type pos = globalCaseName_.find
+    (
+        "processor",
+        (sep == string::npos ? 0 : sep)
+    );
+
+    if (pos == 0)
+    {
+        globalCaseName_ = ".";
+        processorCase_  = true;
+    }
+    else if (pos != string::npos && sep != string::npos && sep == pos-1)
+    {
+        globalCaseName_.resize(sep);
+        processorCase_  = true;
+    }
+
+    return processorCase_;
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::TimePaths::TimePaths
@@ -38,29 +70,13 @@ Foam::TimePaths::TimePaths
 :
     processorCase_(false),
     rootPath_(rootPath),
+    globalCaseName_(caseName),
     case_(caseName),
     system_(systemName),
     constant_(constantName)
 {
     // Find out from case name whether a processor directory
-    std::string::size_type pos = caseName.find("processor");
-    if (pos != string::npos)
-    {
-        processorCase_ = true;
-
-        if (pos == 0)
-        {
-            globalCaseName_ = ".";
-        }
-        else
-        {
-            globalCaseName_ = caseName(pos-1);
-        }
-    }
-    else
-    {
-        globalCaseName_ = caseName;
-    }
+    detectProcessorCase();
 }
 
 
@@ -81,27 +97,10 @@ Foam::TimePaths::TimePaths
     system_(systemName),
     constant_(constantName)
 {
-    if (!processorCase)
-    {
-        // For convenience: find out from case name whether it is a
-        // processor directory and set processorCase flag so file searching
-        // goes up one level.
-        std::string::size_type pos = caseName.find("processor");
-
-        if (pos != string::npos)
-        {
-            processorCase_ = true;
-
-            if (pos == 0)
-            {
-                globalCaseName_ = ".";
-            }
-            else
-            {
-                globalCaseName_ = caseName(pos-1);
-            }
-        }
-    }
+    // For convenience: find out from case name whether it is a
+    // processor directory and set processorCase flag so file searching
+    // goes up one level.
+    detectProcessorCase();
 }
 
 
diff --git a/src/OpenFOAM/db/Time/TimePaths.H b/src/OpenFOAM/db/Time/TimePaths.H
index 88943ca61f2..f7bbc25d295 100644
--- a/src/OpenFOAM/db/Time/TimePaths.H
+++ b/src/OpenFOAM/db/Time/TimePaths.H
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011-2014 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -59,6 +59,12 @@ class TimePaths
         const word constant_;
 
 
+    // Private Member functions
+
+        //- Determine from case name whether it is a processor directory
+        bool detectProcessorCase();
+
+
 public:
 
     // Constructors
-- 
GitLab