]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Better structure some code in the gmsh wrappers. 16230/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 1 Nov 2023 00:44:46 +0000 (18:44 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 1 Nov 2023 00:44:46 +0000 (18:44 -0600)
include/deal.II/gmsh/utilities.h
source/gmsh/utilities.cc

index f5d00f0ccf1df8fb68a921f6b23eeb1f987582f0..a3e9461e7d984d5c15d5f30f5ddf928fc3016783 100644 (file)
@@ -70,12 +70,15 @@ namespace Gmsh
     double characteristic_length = 1.0;
 
     /**
-     * Basename for the output files.
+     * Base name for the output files. The base name may contain a directory
+     * (followed by a slash), and must contain the base of the names of files
+     * to be created.
      *
-     * If this is left empty, then temporary files are used, and removed when
-     * not needed any more.
+     * If this variable is left empty, then a temporary directory will be used,
+     * and both the files written into it as well as the temporary directory
+     * will be removed when not needed any more.
      */
-    std::string output_base_name = "";
+    std::string output_base_name = {};
   };
 
 #  ifdef DEAL_II_WITH_OPENCASCADE
index b37e0a3573559e95fbb152920d357c6866a35f6d..4fbad7db668125265d1c92d3e08136e3ddfe34f4 100644 (file)
@@ -59,11 +59,16 @@ namespace Gmsh
                                            Triangulation<2, spacedim> &tria,
                                            const AdditionalParameters &prm)
   {
-    std::string base_name      = prm.output_base_name;
-    char        dir_template[] = "ctfbc-XXXXXX";
-    if (base_name.empty())
+    std::string base_name = prm.output_base_name;
+
+    // If necessary, create a temp directory to put files into. The
+    // following variable will hold the name of the tmp dir; it is
+    // initialized with a template, and 'mkdtemp' then overwrites it
+    // with the name of the directory it creates.
+    char tmp_dir_name[] = "ctfbc-XXXXXX";
+    if (prm.output_base_name.empty())
       {
-        const char *temp = mkdtemp(dir_template);
+        const char *temp = mkdtemp(tmp_dir_name);
         AssertThrow(temp != nullptr,
                     ExcMessage("Creating temporary directory failed!"));
         base_name = temp;
@@ -105,7 +110,8 @@ namespace Gmsh
     gridin.attach_triangulation(tria);
     gridin.read_msh(grid_file);
 
-    if (base_name != prm.output_base_name)
+    // Clean up files if a tmp directory was used:
+    if (prm.output_base_name.empty())
       {
         // declaring the list without a type, i.e.,
         //
@@ -125,10 +131,12 @@ namespace Gmsh
             AssertThrow(ret_value == 0,
                         ExcMessage("Failed to remove " + *filename));
           }
-        const auto ret_value = std::remove(dir_template);
+
+        // Finally also remove the tmp directory:
+        const auto ret_value = std::remove(tmp_dir_name);
         AssertThrow(ret_value == 0,
                     ExcMessage("Failed to remove " +
-                               std::string(dir_template)));
+                               std::string(tmp_dir_name)));
       }
   }
 #  endif

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.