From bca8bd0cbbac67caae3a42925d06e1c69618c31e Mon Sep 17 00:00:00 2001
From: rinkk <karsten.rink@ufz.de>
Date: Fri, 27 Nov 2020 09:58:48 +0100
Subject: [PATCH] [baselib] moved file removal to baselib

---
 .../MeshGeoTools/VerticalSliceFromLayers.cpp    | 17 ++++-------------
 BaseLib/FileTools.cpp                           | 15 ++++++++++-----
 BaseLib/FileTools.h                             |  4 ++++
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp b/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp
index 873403f83ea..b38b66222c3 100644
--- a/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp
+++ b/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp
@@ -43,16 +43,6 @@
 
 #include <QApplication>
 
-/// deletes temporary output files
-void removeFile(std::string const& filename)
-{
-    std::string remove_cmd("rm " + filename);
-#ifdef _WIN32
-    remove_cmd = "del " + filename;
-#endif
-    system(remove_cmd.c_str());
-}
-
 /// reads the list of mesh files into a string vector
 std::vector<std::string> readLayerFile(std::string const& layer_file)
 {
@@ -239,7 +229,8 @@ void consolidateGeometry(GeoLib::GEOObjects& geo,
 
     if (!keep_gml_file)
     {
-        removeFile(filename);
+        BaseLib::removeFile(filename);
+        BaseLib::removeFile(filename + ".md5");
     }
 }
 
@@ -398,8 +389,8 @@ int main(int argc, char* argv[])
         generateMesh(geo, merged_geo_name, output_name, interval_length));
     if (!test_arg.getValue())
     {
-        removeFile(output_name + ".geo");
-        removeFile(output_name + ".msh");
+        BaseLib::removeFile(output_name + ".geo");
+        BaseLib::removeFile(output_name + ".msh");
     }
     if (mesh == nullptr)
     {
diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index 588e7b50a08..7a9ad4b1995 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -226,15 +226,20 @@ void setProjectDirectory(std::string const& dir)
     project_directory_is_set = true;
 }
 
+void removeFile(std::string const& filename)
+{
+    bool const success = fs::remove(fs::path(filename));
+    if (success)
+    {
+        DBUG("Removed '{:s}'", filename);
+    }
+}
+
 void removeFiles(std::vector<std::string> const& files)
 {
     for (auto const& file : files)
     {
-        bool const success = fs::remove(fs::path(file));
-        if (success)
-        {
-            DBUG("Removed '{:s}'", file);
-        }
+        removeFile(file);
     }
 }
 } // end namespace BaseLib
diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h
index 40478b0fbdf..68280087407 100644
--- a/BaseLib/FileTools.h
+++ b/BaseLib/FileTools.h
@@ -183,6 +183,10 @@ std::string const& getProjectDirectory();
 /// Sets the project directory.
 void setProjectDirectory(std::string const& dir);
 
+/// Removes a file. If a file does not exist nothing will happen, other errors
+/// lead to OGS_FATAL call.
+void removeFile(std::string const& filename);
+
 /// Remove files. If a file does not exist nothing will happen, other errors
 /// lead to OGS_FATAL call.
 void removeFiles(std::vector<std::string> const& files);
-- 
GitLab