Tolerate unknown files in repodata dirs - Ville Skyttä
authorPaul Nasrat <pnasrat@redhat.com>
Wed, 19 Jul 2006 12:29:47 +0000 (12:29 +0000)
committerPaul Nasrat <pnasrat@redhat.com>
Wed, 19 Jul 2006 12:29:47 +0000 (12:29 +0000)
genpkgmetadata.py

index d4e612d25c2b69efffd5eaf37d06a3e6214ebb57..c58d6b3b5ecd4f92c65aa12429750670a98c8297 100755 (executable)
@@ -27,6 +27,7 @@ import rpm
 import libxml2
 import string
 import fnmatch
+import shutil
 
 import dumpMetadata
 from dumpMetadata import _gzipOpen
@@ -552,6 +553,31 @@ def main(args):
                 errorprint(_('Error was %s') % e)
                 sys.exit(1)
 
+    # Move everything else back from olddir (eg. repoview files)
+    olddir = os.path.join(cmds['outputdir'], cmds['olddir'])
+    finaldir = os.path.join(cmds['outputdir'], cmds['finaldir'])
+    for file in os.listdir(olddir):
+        oldfile = os.path.join(olddir, file)
+        finalfile = os.path.join(finaldir, file)
+        if os.path.exists(finalfile):
+            # Hmph?  Just leave it alone, then.
+            try:
+                if os.path.isdir(oldfile):
+                    shutil.rmtree(oldfile)
+                else:
+                    os.remove(oldfile)
+            except OSError, e:
+                errorprint(_('Could not remove old non-metadata file: %s') % oldfile)
+                errorprint(_('Error was %s') % e)
+                sys.exit(1)
+        else:
+            try:
+                os.rename(oldfile, finalfile)
+            except OSError, e:
+                errorprint(_('Could not restore old non-metadata file: %s -> %s') % (oldfile, finalfile))
+                errorprint(_('Error was %s') % e)
+                sys.exit(1)
+
 #XXX: fix to remove tree as we mung basedir
     try:
         os.rmdir(os.path.join(cmds['outputdir'], cmds['olddir']))