From ff93da4508ef48d62f7bf699fff5faebf542153b Mon Sep 17 00:00:00 2001
From: Christoph Lehmann <christoph.lehmann@ufz.de>
Date: Thu, 13 Jun 2024 10:15:20 +0200
Subject: [PATCH] Changed handling of relative mesh paths in prj file

---
 Applications/ApplicationsLib/ProjectData.cpp | 13 ++++++++++++-
 BaseLib/FileTools.cpp                        |  7 +------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp
index 0d542c996a5..78fbcaf75d6 100644
--- a/Applications/ApplicationsLib/ProjectData.cpp
+++ b/Applications/ApplicationsLib/ProjectData.cpp
@@ -185,8 +185,19 @@ std::unique_ptr<MeshLib::Mesh> readSingleMesh(
         mesh_file, true /* compute_element_neighbors */));
     if (!mesh)
     {
+        std::filesystem::path abspath{mesh_file};
+        try
+        {
+            abspath = std::filesystem::absolute(mesh_file);
+        }
+        catch (std::filesystem::filesystem_error const& e)
+        {
+            ERR("Determining the absolute path of '{}' failed: {}", mesh_file,
+                e.what());
+        }
+
         OGS_FATAL("Could not read mesh from '{:s}' file. No mesh added.",
-                  mesh_file);
+                  abspath.string());
     }
 
 #ifdef DOXYGEN_DOCU_ONLY
diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index 4b7a506e9cc..ba481fb62f6 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -203,12 +203,7 @@ bool hasFileExtension(std::string const& extension, std::string const& filename)
 std::string copyPathToFileName(const std::string& file_name,
                                const std::string& source)
 {
-    auto filePath = std::filesystem::path(file_name);
-    if (filePath.has_parent_path())
-    {
-        return filePath.string();
-    }
-    return (std::filesystem::path(source) /= filePath).string();
+    return (std::filesystem::path(source) / file_name).string();
 }
 
 std::string extractPath(std::string const& pathname)
-- 
GitLab