From: Joel Rosdahl Date: Tue, 8 Sep 2020 18:05:58 +0000 (+0200) Subject: Simplify TemporaryFile X-Git-Tag: v4.0~117 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b409fafb5ecff8298ddf0fbf16367b1830a1a452;p=thirdparty%2Fccache.git Simplify TemporaryFile --- diff --git a/src/TemporaryFile.cpp b/src/TemporaryFile.cpp index 285654f48..0c64f5ec3 100644 --- a/src/TemporaryFile.cpp +++ b/src/TemporaryFile.cpp @@ -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); -} diff --git a/src/TemporaryFile.hpp b/src/TemporaryFile.hpp index ca40b4821..3aae4f90e 100644 --- a/src/TemporaryFile.hpp +++ b/src/TemporaryFile.hpp @@ -41,7 +41,4 @@ public: // The actual filename. Empty on error. std::string path; - -private: - bool initialize(nonstd::string_view path_prefix); };