From 1505bcf73c12d6d728a68e8d531595db538686e5 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 26 Sep 2024 09:44:09 +0200 Subject: [PATCH 1/2] chain: No need to re-create resultdir This is already handled by the preceding resetLogging() call. Relates: #1467 --- mock/py/mockbuild/backend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mock/py/mockbuild/backend.py b/mock/py/mockbuild/backend.py index 200709bde..63b063c88 100644 --- a/mock/py/mockbuild/backend.py +++ b/mock/py/mockbuild/backend.py @@ -477,7 +477,6 @@ def chain(self, args, options, buildroot): resultdir = os.path.join(self.config['local_repo_dir'], pdn) self.buildroot.resultdir = resultdir self.buildroot.resetLogging(force=True) - file_util.mkdirIfAbsent(resultdir) success_file = os.path.join(resultdir, 'success') build_ret_code = 0 try: From a0155c50fee1ed723dec2b7bd49ca24b0ac4149a Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Thu, 26 Sep 2024 09:51:15 +0200 Subject: [PATCH 2/2] chroot_scan: create result directory with appropriate permissions To make the fix possible, we needed to make the result directory creation method public. Fixes: #1467 --- mock/py/mockbuild/buildroot.py | 16 +++++++++++----- mock/py/mockbuild/plugins/chroot_scan.py | 4 ++-- .../unified-resultdir-preparation.bugfix | 5 +++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 releng/release-notes-next/unified-resultdir-preparation.bugfix diff --git a/mock/py/mockbuild/buildroot.py b/mock/py/mockbuild/buildroot.py index 8c34bb711..2cb3eaf5a 100644 --- a/mock/py/mockbuild/buildroot.py +++ b/mock/py/mockbuild/buildroot.py @@ -52,6 +52,7 @@ def wrapper(*args, **kwargs): class Buildroot(object): + # pylint: disable=too-many-public-methods,too-many-instance-attributes @traceLog() def __init__(self, config, uid_manager, state, plugins, bootstrap_buildroot=None, is_bootstrap=False): self.config = config @@ -213,13 +214,18 @@ def _setup_basedir(self): os.chmod(self.basedir, 0o775) @traceLog() - def _setup_result_dir(self): + def create_resultdir(self): + """ + (re)create self.resultdir directory with appropriate permissions + """ self._setup_basedir() with self.uid_manager: try: file_util.mkdirIfAbsent(self.resultdir) - except Error: - raise ResultDirNotAccessible(ResultDirNotAccessible.__doc__ % self.resultdir) + except Error as err: + raise ResultDirNotAccessible( + ResultDirNotAccessible.__doc__ % self.resultdir + ) from err @traceLog() @@ -300,7 +306,7 @@ def _init(self, prebuild): # intentionally we do not call bootstrap hook here - it does not have sense self._setup_nosync() self.chroot_was_initialized = self.chroot_is_initialized() - self._setup_result_dir() + self.create_resultdir() getLog().info("calling preinit hooks") self.plugins.call_hooks('preinit') # intentionally we do not call bootstrap hook here - it does not have sense @@ -629,7 +635,7 @@ def resetLogging(self, force=False): return self.logging_initialized = True - self._setup_result_dir() + self.create_resultdir() with self.uid_manager: # attach logs to log files. diff --git a/mock/py/mockbuild/plugins/chroot_scan.py b/mock/py/mockbuild/plugins/chroot_scan.py index 539c7d34d..56f729367 100644 --- a/mock/py/mockbuild/plugins/chroot_scan.py +++ b/mock/py/mockbuild/plugins/chroot_scan.py @@ -13,7 +13,7 @@ # our imports from mockbuild.trace_decorator import getLog, traceLog -from mockbuild import file_util, util +from mockbuild import util requires_api_version = "1.1" @@ -56,7 +56,7 @@ def __scanChroot(self): regexstr = "|".join(self.scan_opts['regexes']) regex = re.compile(regexstr) chroot = self.buildroot.make_chroot_path() - file_util.mkdirIfAbsent(self.resultdir) + self.buildroot.create_resultdir() count = 0 logger = getLog() logger.debug("chroot_scan: Starting scan of %s", chroot) diff --git a/releng/release-notes-next/unified-resultdir-preparation.bugfix b/releng/release-notes-next/unified-resultdir-preparation.bugfix new file mode 100644 index 000000000..0211f08b2 --- /dev/null +++ b/releng/release-notes-next/unified-resultdir-preparation.bugfix @@ -0,0 +1,5 @@ +Several internal code locations attempt to ensure that the result directory +exists, creating it if necessary. However, these locations handled it +inconsistently, sometimes neglecting to [change the ownership][issue#1467] of +the result directory. Now, all locations use a single method dedicated to +result directory preparation.