]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Make Config noncopyable and add clear_and_reset() method (#522)
authorThomas Otto <thomas.otto@pdv-fs.de>
Sat, 25 Jan 2020 12:45:42 +0000 (13:45 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 25 Jan 2020 12:45:42 +0000 (13:45 +0100)
Prevents changes from getting lost by writing them to a
temporary copy of the main Config object.

Also restore deleted comments from the move of
primary/secondary_config_path.

src/Config.cpp
src/Config.hpp
src/ccache.cpp

index 34ee5899c79a704d4afe246a8ef6a0b9e8f38ff8..5ed1fd893efc347b530c3988b411f5c78f417c16 100644 (file)
@@ -652,6 +652,11 @@ Config::set_value_in_file(const std::string& path,
   output.commit();
 }
 
+void Config::clear_and_reset()
+{
+  *this = Config();
+}
+
 void
 Config::visit_items(const ItemVisitor& item_visitor) const
 {
index 2b8bb77d02ed5250eca7e0d9075bee5b60348bbe..dabf238c6d2713fe8045f0352459bd53155f69da 100644 (file)
@@ -36,6 +36,8 @@ extern Config g_config;
 class Config
 {
 public:
+  Config() = default;
+
   const std::string& base_dir() const;
   const std::string& cache_dir() const;
   uint32_t cache_dir_levels() const;
@@ -81,8 +83,11 @@ public:
   void set_max_size(uint64_t value);
   void set_run_second_cpp(bool value);
 
+  // Where to write configuration changes.
   const std::string& primary_config_path() const;
+  // Secondary, read-only configuration file (if any).
   const std::string& secondary_config_path() const;
+
   void set_primary_config_path(std::string path);
   void set_secondary_config_path(std::string path);
 
@@ -111,6 +116,9 @@ public:
                                 const std::string& key,
                                 const std::string& value);
 
+  // Clear the Config object and reset all values to defaults.
+  void clear_and_reset();
+
 private:
   std::string m_primary_config_path;
   std::string m_secondary_config_path;
@@ -157,6 +165,10 @@ private:
                 const nonstd::optional<std::string>& env_var_key,
                 bool negate,
                 const std::string& origin);
+
+  // These exist, but are private to be used in clear_and_reset()
+  Config(const Config&) = default;
+  Config& operator=(const Config&) = default;
 };
 
 inline const std::string&
index efec49f06d71847d3fbd4c6e29c0f69884bcc236..8fabe737885d08ae089d7e5f310cdf729c63264b 100644 (file)
@@ -3698,7 +3698,7 @@ free_and_nullify(T*& ptr)
 void
 cc_reset(void)
 {
-  g_config = Config();
+  g_config.clear_and_reset();
 
   free_and_nullify(current_working_dir);
   for (size_t i = 0; i < debug_prefix_maps_len; i++) {