]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Simplify TemporaryFile
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 8 Sep 2020 18:05:58 +0000 (20:05 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 8 Sep 2020 18:31:54 +0000 (20:31 +0200)
src/TemporaryFile.cpp
src/TemporaryFile.hpp

index 285654f48f5acbad4c63b8089ab993b392705968..0c64f5ec3de8ddca44863dd802187c88082159cd 100644 (file)
@@ -59,14 +59,10 @@ mkstemp(char* name_template)
 } // namespace
 
 TemporaryFile::TemporaryFile(string_view path_prefix)
+  : path(std::string(path_prefix) + ".XXXXXX")
 {
-  if (!initialize(path_prefix) && errno == ENOENT) {
-    auto dir = Util::dir_name(path);
-    if (!Util::create_dir(dir)) {
-      throw Fatal("Failed to create directory {}: {}", dir, strerror(errno));
-    }
-    initialize(path_prefix);
-  }
+  Util::ensure_dir_exists(Util::dir_name(path));
+  fd = Fd(mkstemp(&path[0]));
   if (!fd) {
     throw Fatal(
       "Failed to create temporary file for {}: {}", path, strerror(errno));
@@ -77,12 +73,3 @@ TemporaryFile::TemporaryFile(string_view path_prefix)
   fchmod(*fd, 0666 & ~get_umask());
 #endif
 }
-
-bool
-TemporaryFile::initialize(string_view path_prefix)
-{
-  path = std::string(path_prefix);
-  path += ".XXXXXX";
-  fd = Fd(mkstemp(&path[0]));
-  return bool(fd);
-}
index ca40b4821134060fe5ffce3d780dafbd4868d5e1..3aae4f90ea655db6e8d566fef930c4acd15cec82 100644 (file)
@@ -41,7 +41,4 @@ public:
 
   // The actual filename. Empty on error.
   std::string path;
-
-private:
-  bool initialize(nonstd::string_view path_prefix);
 };