]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move UmaskScope to util
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 14 Jul 2023 18:46:37 +0000 (20:46 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 15 Jul 2023 19:03:53 +0000 (21:03 +0200)
src/Config.cpp
src/ccache.cpp
src/core/mainoptions.cpp
src/storage/remote/FileStorage.cpp
src/util/CMakeLists.txt
src/util/UmaskScope.cpp [moved from src/UmaskScope.hpp with 72% similarity]
src/util/UmaskScope.hpp [new file with mode: 0644]

index f7fef61ae7614483b69c7593ce5a7a94bfe0b607..b508ae4dc35b2f1b0e4f6c13b71b6bd4f3877e8c 100644 (file)
 #include "Util.hpp"
 #include "assertions.hpp"
 
-#include <UmaskScope.hpp>
 #include <core/exceptions.hpp>
 #include <core/types.hpp>
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
 #include <util/Tokenizer.hpp>
+#include <util/UmaskScope.hpp>
 #include <util/environment.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
@@ -859,7 +859,7 @@ Config::set_value_in_file(const std::string& path,
                           const std::string& key,
                           const std::string& value) const
 {
-  UmaskScope umask_scope(m_umask);
+  util::UmaskScope umask_scope(m_umask);
 
   if (k_config_key_table.find(key) == k_config_key_table.end()) {
     throw core::Error(FMT("unknown configuration option \"{}\"", key));
index c7e85826420ef3b7a4de77f7a9c0d14d34fcdb0b..75dc41b604a01df915f86f9c147b063ff17d03f1 100644 (file)
@@ -1,5 +1,5 @@
-// Copyright (C) 2002-2007 Andrew Tridgell
 // Copyright (C) 2009-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2002-2007 Andrew Tridgell
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -31,7 +31,6 @@
 #include "MiniTrace.hpp"
 #include "SignalHandler.hpp"
 #include "TemporaryFile.hpp"
-#include "UmaskScope.hpp"
 #include "Util.hpp"
 #include "Win32Util.hpp"
 #include "argprocessing.hpp"
 #include <core/types.hpp>
 #include <core/wincompat.hpp>
 #include <storage/Storage.hpp>
+#include <util/UmaskScope.hpp>
 #include <util/environment.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
 #include <util/path.hpp>
+#include <util/process.hpp>
 #include <util/string.hpp>
 
 #include "third_party/fmt/core.h"
@@ -767,7 +768,7 @@ result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
 static nonstd::expected<DoExecuteResult, Failure>
 do_execute(Context& ctx, Args& args, const bool capture_stdout = true)
 {
-  UmaskScope umask_scope(ctx.original_umask);
+  util::UmaskScope umask_scope(ctx.original_umask);
 
   if (ctx.diagnostics_color_failed) {
     DEBUG_ASSERT(ctx.config.compiler_type() == CompilerType::gcc);
@@ -2121,7 +2122,7 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Hash::Digest& result_key)
     cache_entry.verify_checksum();
     core::Result::Deserializer deserializer(cache_entry.payload());
     core::ResultRetriever result_retriever(ctx, result_key);
-    UmaskScope umask_scope(ctx.original_umask);
+    util::UmaskScope umask_scope(ctx.original_umask);
     deserializer.visit(result_retriever);
   } catch (core::ResultRetriever::WriteError& e) {
     LOG("Write error when retrieving result from {}: {}",
index 9703f21e6b9da72afa113906174186ff8d972672..3ec634f6fe3e5751e70da17a10dd393b0a00dc3b 100644 (file)
@@ -27,7 +27,6 @@
 #include <ProgressBar.hpp>
 #include <TemporaryFile.hpp>
 #include <ThreadPool.hpp>
-#include <UmaskScope.hpp>
 #include <Util.hpp>
 #include <assertions.hpp>
 #include <ccache.hpp>
@@ -44,6 +43,7 @@
 #include <storage/Storage.hpp>
 #include <storage/local/LocalStorage.hpp>
 #include <util/TextTable.hpp>
+#include <util/UmaskScope.hpp>
 #include <util/XXH3_128.hpp>
 #include <util/environment.hpp>
 #include <util/expected.hpp>
@@ -561,7 +561,7 @@ process_main_options(int argc, const char* const* argv)
     config.read();
     Logging::init(config);
 
-    UmaskScope umask_scope(config.umask());
+    util::UmaskScope umask_scope(config.umask());
 
     const std::string arg = optarg ? optarg : std::string();
 
index 648e9504c7c323e67efc4d947c7be790acf81cc9..4b6125068f56ee0ac8c8821812c1871bea3c422a 100644 (file)
 
 #include <AtomicFile.hpp>
 #include <Logging.hpp>
-#include <UmaskScope.hpp>
 #include <Util.hpp>
 #include <assertions.hpp>
 #include <core/exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <util/Bytes.hpp>
+#include <util/UmaskScope.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
 #include <util/string.hpp>
@@ -145,7 +145,7 @@ FileStorageBackend::put(const Hash::Digest& key,
   }
 
   {
-    UmaskScope umask_scope(m_umask);
+    util::UmaskScope umask_scope(m_umask);
 
     const auto dir = Util::dir_name(path);
     if (!Util::create_dir(dir)) {
index d1d5925a84bc73266ef0a050e548044d53f377b0..1739c1dafeb3e8b1ee8a285355a2851f0e96bfc9 100644 (file)
@@ -6,6 +6,7 @@ set(
   TextTable.cpp
   TimePoint.cpp
   Tokenizer.cpp
+  UmaskScope.cpp
   environment.cpp
   file.cpp
   path.cpp
similarity index 72%
rename from src/UmaskScope.hpp
rename to src/util/UmaskScope.cpp
index 88867ed3af57b7d36508643a6f89f47573b3a957..add2a7ca4ed6f179636ab690d49931fced0be4d6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-#pragma once
+#include "UmaskScope.hpp"
 
 #include <util/process.hpp>
 
 #include <sys/stat.h>
-#include <sys/types.h>
 
-#include <optional>
+namespace util {
 
-// This class sets a new (process-global) umask and restores the previous umask
-// when destructed.
-class UmaskScope
-{
-public:
-  UmaskScope(std::optional<mode_t> new_umask);
-  ~UmaskScope();
-
-  void release();
-
-private:
-  std::optional<mode_t> m_saved_umask = std::nullopt;
-};
-
-inline UmaskScope::UmaskScope(std::optional<mode_t> new_umask)
+UmaskScope::UmaskScope(std::optional<mode_t> new_umask)
 {
 #ifndef _WIN32
   if (new_umask) {
@@ -50,12 +35,7 @@ inline UmaskScope::UmaskScope(std::optional<mode_t> new_umask)
 #endif
 }
 
-inline UmaskScope::~UmaskScope()
-{
-  release();
-}
-
-inline void
+void
 UmaskScope::release()
 {
 #ifndef _WIN32
@@ -73,3 +53,5 @@ UmaskScope::release()
   }
 #endif
 }
+
+} // namespace util
diff --git a/src/util/UmaskScope.hpp b/src/util/UmaskScope.hpp
new file mode 100644 (file)
index 0000000..1bdbabd
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#pragma once
+
+#include <sys/types.h>
+
+#include <optional>
+
+namespace util {
+
+// This class sets a new (process-global) umask and restores the previous umask
+// when destructed.
+class UmaskScope
+{
+public:
+  UmaskScope(std::optional<mode_t> new_umask);
+  ~UmaskScope();
+
+  void release();
+
+private:
+  std::optional<mode_t> m_saved_umask = std::nullopt;
+};
+
+inline UmaskScope::~UmaskScope()
+{
+  release();
+}
+
+} // namespace util