Explicitly remove all temporary files
There is no guarantee __del__ will ever be called, and we were leaving a ton of stuff in /tmp. With this patch we pass the temporary directories explictly and make sure they are deleted at the end. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
fe026bb588
commit
35e72df99f
|
@ -4,13 +4,12 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import tempfile
|
|
||||||
import shutil
|
|
||||||
|
|
||||||
import pungi.ks
|
import pungi.ks
|
||||||
from pungi.dnf_wrapper import DnfWrapper, Conf
|
from pungi.dnf_wrapper import DnfWrapper, Conf
|
||||||
from pungi.gather_dnf import Gather, GatherOptions
|
from pungi.gather_dnf import Gather, GatherOptions
|
||||||
from pungi.profiler import Profiler
|
from pungi.profiler import Profiler
|
||||||
|
from pungi.util import temp_dir
|
||||||
|
|
||||||
|
|
||||||
def get_parser():
|
def get_parser():
|
||||||
|
@ -68,12 +67,13 @@ def get_parser():
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(persistdir, cachedir):
|
||||||
parser = get_parser()
|
parser = get_parser()
|
||||||
ns = parser.parse_args()
|
ns = parser.parse_args()
|
||||||
|
|
||||||
dnf_conf = Conf(ns.arch)
|
dnf_conf = Conf(ns.arch)
|
||||||
dnf_conf.persistdir = tempfile.mkdtemp()
|
dnf_conf.persistdir = persistdir
|
||||||
|
dnf_conf.cachedir = cachedir
|
||||||
dnf_obj = DnfWrapper(dnf_conf)
|
dnf_obj = DnfWrapper(dnf_conf)
|
||||||
|
|
||||||
gather_opts = GatherOptions()
|
gather_opts = GatherOptions()
|
||||||
|
@ -129,7 +129,6 @@ def main():
|
||||||
packages.add("-%s" % i)
|
packages.add("-%s" % i)
|
||||||
|
|
||||||
g.gather(packages, conditional_packages)
|
g.gather(packages, conditional_packages)
|
||||||
shutil.rmtree(dnf_conf.persistdir)
|
|
||||||
|
|
||||||
print_rpms(g)
|
print_rpms(g)
|
||||||
if ns.profiler:
|
if ns.profiler:
|
||||||
|
@ -162,4 +161,6 @@ def print_rpms(gather_obj):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
with temp_dir(prefix='pungi_dnf_') as persistdir:
|
||||||
|
with temp_dir(prefix='pungi_dnf_cache_') as cachedir:
|
||||||
|
main(persistdir, cachedir)
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
import dnf
|
import dnf
|
||||||
|
|
||||||
|
@ -56,12 +54,6 @@ class DnfWrapper(dnf.Base):
|
||||||
super(DnfWrapper, self).__init__(*args, **kwargs)
|
super(DnfWrapper, self).__init__(*args, **kwargs)
|
||||||
self.arch_wrapper = ArchWrapper(self.conf.substitutions["arch"])
|
self.arch_wrapper = ArchWrapper(self.conf.substitutions["arch"])
|
||||||
self.comps_wrapper = CompsWrapper(self)
|
self.comps_wrapper = CompsWrapper(self)
|
||||||
# use a custom cachedir, delete it after use
|
|
||||||
self.conf.cachedir = tempfile.mkdtemp(prefix="pungi_dnf_")
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
if self.conf.cachedir.startswith("/tmp/"):
|
|
||||||
shutil.rmtree(self.conf.cachedir)
|
|
||||||
|
|
||||||
def add_repo(self, repoid, baseurl=None, mirrorlist=None, ignoregroups=False, lookaside=False):
|
def add_repo(self, repoid, baseurl=None, mirrorlist=None, ignoregroups=False, lookaside=False):
|
||||||
if "://" not in baseurl:
|
if "://" not in baseurl:
|
||||||
|
|
|
@ -1621,6 +1621,7 @@ def convert_dnf_packages(pkgs, flags):
|
||||||
class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase):
|
class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(DNFDepsolvingTestCase, self).setUp()
|
super(DNFDepsolvingTestCase, self).setUp()
|
||||||
|
self.cachedir = os.path.join(self.tmp_dir, 'pungi_dnf_cache')
|
||||||
self.get_langpacks = False
|
self.get_langpacks = False
|
||||||
|
|
||||||
logger = logging.getLogger('gather_dnf')
|
logger = logging.getLogger('gather_dnf')
|
||||||
|
@ -1665,6 +1666,7 @@ class DNFDepsolvingTestCase(DepsolvingBase, unittest.TestCase):
|
||||||
def dnf_instance(self, base_arch, exclude=None, lookaside=False, persistdir=None):
|
def dnf_instance(self, base_arch, exclude=None, lookaside=False, persistdir=None):
|
||||||
conf = Conf(base_arch)
|
conf = Conf(base_arch)
|
||||||
conf.persistdir = persistdir
|
conf.persistdir = persistdir
|
||||||
|
conf.cachedir = self.cachedir
|
||||||
if exclude:
|
if exclude:
|
||||||
conf.exclude = exclude
|
conf.exclude = exclude
|
||||||
dnf = DnfWrapper(conf)
|
dnf = DnfWrapper(conf)
|
||||||
|
|
Loading…
Reference in New Issue