From f09d7cfe7f477fb1f8bf5d78a4c859e78d5eab42 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 16 Nov 2020 11:29:05 -0500 Subject: [PATCH] MockModuleBuilder: manage timestamps on mock config files The mod time for the mock configuration file is used to determine whether the root cache is out-of-date or not, so we want to avoid changing the configuration timestamps when we don't change content when we're just writing a per-thread mock configuration file again with no substantive changes. We do this by only updating the master mock.cfg file when we're actually adding content, and propagating its mod time to the per-thread configuration files. --- .../builder/MockModuleBuilder.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/module_build_service/builder/MockModuleBuilder.py b/module_build_service/builder/MockModuleBuilder.py index d4a3d888..0f610b67 100644 --- a/module_build_service/builder/MockModuleBuilder.py +++ b/module_build_service/builder/MockModuleBuilder.py @@ -468,7 +468,7 @@ class MockModuleBuilder(GenericBuilder): self.enabled_modules = config_opts["module_enable"] self.releasever = config_opts["releasever"] - def _write_mock_config(self): + def _write_mock_config(self, update_main=False): """ Writes Mock config file to local file. """ @@ -483,11 +483,15 @@ class MockModuleBuilder(GenericBuilder): config = config.replace("$enabled_modules", str(self.enabled_modules)) config = config.replace("$releasever", str(self.releasever)) - # We write the most recent config to "mock.cfg", so thread-related - # configs can be later (re-)generated from it using _load_mock_config. - outfile = os.path.join(self.configdir, "mock.cfg") - with open(outfile, "w") as f: - f.write(config) + + mock_cfg_path = os.path.join(self.configdir, "mock.cfg") + if update_main or not os.path.exists(mock_cfg_path): + # We write a config to "mock.cfg", so thread-related + # configs can be later (re-)generated from it using _load_mock_config. + with open(mock_cfg_path, "w") as f: + f.write(config) + + mtime = os.path.getmtime(mock_cfg_path) # Write the config to thread-related configuration file. outfile = os.path.join( @@ -495,6 +499,8 @@ class MockModuleBuilder(GenericBuilder): with open(outfile, "w") as f: f.write(config) + os.utime(outfile, (mtime, mtime)) + def buildroot_connect(self, groups): self._load_mock_config() self.groups = list(set().union(groups["build"], self.groups)) @@ -525,7 +531,7 @@ class MockModuleBuilder(GenericBuilder): if artifact and artifact.startswith("module-build-macros"): self._load_mock_config() self.groups.append("module-build-macros") - self._write_mock_config() + self._write_mock_config(update_main=True) events.scheduler.add(repos_done_handler, ("fake_msg", self.tag_name + "-build")) @@ -586,7 +592,7 @@ class MockModuleBuilder(GenericBuilder): baseurl = "file://" + repo_dir self._add_repo(repo_name, baseurl) - self._write_mock_config() + self._write_mock_config(update_main=True) def _send_build_change(self, state, source, build_id): from module_build_service.scheduler.handlers.components import (