]> git.ipfire.org Git - pakfire.git/commitdiff
builder: Initialise Pakfire() when entering context
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Jan 2021 17:24:00 +0000 (17:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Jan 2021 17:24:00 +0000 (17:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/builder.py

index 563539c5654ecc5c826ab95a13fd41e605194db2..9ad87a1937540baba8c1c9a49650fb8440ff497a 100644 (file)
@@ -121,25 +121,6 @@ class Builder(object):
                if self.settings.get("private_network", None):
                        _pakfire.unshare(_pakfire.SCHED_CLONE_NEWNET)
 
-               # Create Pakfire instance
-               self.pakfire = base.Pakfire(path=self.path, config=self.config, distro=self.config.distro, arch=arch)
-
-       def __del__(self):
-               """
-                       Releases build environment and clean up
-               """
-               # Umount the build environment
-               self._umountall()
-
-               # Destroy the pakfire instance
-               del self.pakfire
-
-               # Unlock build environment
-               self.unlock()
-
-               # Delete everything
-               self._destroy()
-
        def __enter__(self):
                self.log.debug("Entering %s" % self.path)
 
@@ -148,7 +129,7 @@ class Builder(object):
                        self._mountall()
                except OSError as e:
                        if e.errno == 30: # Read-only FS
-                               raise BuildError("Buildroot is read-only: %s" % self.pakfire.path)
+                               raise BuildError("Buildroot is read-only: %s" % self.path)
 
                        # Raise all other errors
                        raise
@@ -189,6 +170,15 @@ class Builder(object):
                else:
                        util.orphans_kill(self.path)
 
+               # Umount the build environment
+               self._umountall()
+
+               # Unlock build environment
+               self.unlock()
+
+               # Delete everything
+               self._destroy()
+
        def setup_logging(self, logfile):
                if logfile:
                        self.log = log.getChild(self.build_id)
@@ -450,12 +440,19 @@ class BuilderContext(object):
        def __init__(self, builder):
                self.builder = builder
 
-               # Get a reference to Pakfire
-               self.pakfire = self.builder.pakfire
-
                # Get a reference to the logger
                self.log = self.builder.log
 
+               # Initialise Pakfire instance
+               self.pakfire = base.Pakfire(
+                       path=self.builder.path,
+                       config=self.builder.config,
+                       distro=self.builder.config.distro,
+                       arch=self.builder.arch,
+               )
+
+               self.setup()
+
        @property
        def arch(self):
                return self.pakfire.arch