File createrepo-0.9.9-clean_tmp_files.patch of Package createrepo

From b73f374d6ab3c9dd681d9d5dcd8ab2262d73c166 Mon Sep 17 00:00:00 2001
From: Seth Vidal <skvidal@fedoraproject.org>
Date: Thu, 28 Jul 2011 17:03:45 -0400
Subject: [PATCH] add two private methods to help clean up doFinalMove() and
 makes the code a little nicer for how it is called from the cli.

slightly nicer fix for: https://bugzilla.redhat.com/show_bug.cgi?id=581628
---
 createrepo/__init__.py | 25 ++++++++++++++++++-------
 genpkgmetadata.py      |  1 +
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index 8cce31a..30f7422 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -1151,14 +1151,11 @@ def doFinalMove(self):
                     msg += _('Error was %s') % e
                     raise MDError, msg
 
-        try:
-            os.rmdir(output_old_dir)
-        except OSError, e:
-            self.errorlog(_('Could not remove old metadata dir: %s')
-                          % self.conf.olddir)
-            self.errorlog(_('Error was %s') % e)
-            self.errorlog(_('Please clean up this directory manually.'))
+        self._cleanup_tmp_repodata_dir()
+        self._write_out_read_pkgs_list()
+
 
+    def _write_out_read_pkgs_list(self):
         # write out the read_pkgs_list file with self.read_pkgs
         if self.conf.read_pkgs_list:
             try:
@@ -1171,6 +1168,20 @@ def doFinalMove(self):
                               % self.conf.read_pkgs_list)
                 self.errorlog(_('Error was %s') % e)
 
+    def _cleanup_tmp_repodata_dir(self):
+        output_old_dir = os.path.join(self.conf.outputdir, self.conf.olddir)
+        output_temp_dir = os.path.join(self.conf.outputdir, self.conf.tempdir)
+        for dirbase in (self.conf.olddir, self.conf.tempdir):
+            dirpath = os.path.join(self.conf.outputdir, dirbase)
+            if os.path.exists(dirpath):
+                try:
+                    os.rmdir(dirpath)
+                except OSError, e:
+                    self.errorlog(_('Could not remove  temp metadata dir: %s')
+                                  % dirbase)
+                    self.errorlog(_('Error was %s') % e)
+                    self.errorlog(_('Please clean up this directory manually.'))
+        
     def setup_sqlite_dbs(self, initdb=True):
         """sets up the sqlite dbs w/table schemas and db_infos"""
         destdir = os.path.join(self.conf.outputdir, self.conf.tempdir)
diff --git a/genpkgmetadata.py b/genpkgmetadata.py
index 6c9217a..512420b 100755
--- a/genpkgmetadata.py
+++ b/genpkgmetadata.py
@@ -242,6 +242,7 @@ def main(args):
             if mdgen.checkTimeStamps():
                 if mdgen.conf.verbose:
                     print _('repo is up to date')
+                mdgen._cleanup_tmp_repodata_dir()
                 sys.exit(0)
 
         if conf.profile:
-- 
1.8.1.6

From b6c41bc9997b6adcb9e5ccd218a8bd938c04983d Mon Sep 17 00:00:00 2001
From: Seth Vidal <skvidal@fedoraproject.org>
Date: Fri, 12 Aug 2011 12:16:57 -0400
Subject: [PATCH] I think this is the last of the tmp files which are,
 apparently, terribly important to clean up

closes: https://bugzilla.redhat.com/show_bug.cgi?id=730330
---
 createrepo/__init__.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index 2c63bad..e3c18aa 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -639,7 +639,7 @@ def writeMetadataDocs(self, pkglist=[], pkgpath=None):
             # waitfor the workers to finish and as each one comes in
             # open the files they created and write them out to our metadata
             # add up the total pkg counts and return that value
-            worker_tmp_path = tempfile.mkdtemp()
+            self._worker_tmp_path = tempfile.mkdtemp()
             worker_chunks = utils.split_list_into_equal_chunks(pkgfiles,  self.conf.workers)
             worker_cmd_dict = {}
             worker_jobs = {}
@@ -650,7 +650,7 @@ def writeMetadataDocs(self, pkglist=[], pkgpath=None):
                 # make the worker directory
                 workercmdline = []
                 workercmdline.extend(base_worker_cmdline)
-                thisdir = worker_tmp_path + '/' + str(worker_num)
+                thisdir = self._worker_tmp_path + '/' + str(worker_num)
                 if checkAndMakeDir(thisdir):
                     workercmdline.append('--tmpmdpath=%s' % thisdir)
                 else:
@@ -658,7 +658,7 @@ def writeMetadataDocs(self, pkglist=[], pkgpath=None):
                 for (fn, fo) in (('primary.xml', self.primaryfile), 
                            ('filelists.xml', self.flfile),
                            ('other.xml', self.otherfile)):
-                    fnpath = worker_tmp_path + '/' + str(num) + '/' + fn
+                    fnpath = self._worker_tmp_path + '/' + str(num) + '/' + fn
                     if os.path.exists(fnpath):
                         fo.write(open(fnpath, 'r').read())
 
@@ -1189,6 +1189,9 @@ def _cleanup_tmp_repodata_dir(self):
                                   % dirbase)
                     self.errorlog(_('Error was %s') % e)
                     self.errorlog(_('Please clean up this directory manually.'))
+        # our worker tmp path
+        if hasattr(self, '_worker_tmp_path') and os.path.exists(self._worker_tmp_path):
+            shutil.rmtree(self._worker_tmp_path, ignore_errors=True)
         
     def setup_sqlite_dbs(self, initdb=True):
         """sets up the sqlite dbs w/table schemas and db_infos"""
-- 
1.8.1.6
openSUSE Build Service is sponsored by