[PATCH] modifyrepo --remove: fix multiple bugs. BZ 1013626

Zdenek Pavlas <[email protected]> Mon, 30 Sep 2013 16:05:30 +0200
Newsgroups gmane.linux.rpm.metadata
Message-ID <[email protected]>
- Fix mdtype autodetection from filename.

Now we should correctly derive mdtype even if the file argument
used full path, and/or --unique-md-filenames was on.

- Remove metadata file using path relative to repodir.

See the BZ, unlink should work from any $cwd.

- Honor --mdtype option

When --mdtype is specified, it overrides mdtype autodetection.
This should work for --remove, too.
---
 modifyrepo.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/modifyrepo.py b/modifyrepo.py
index 804a243..8d6366a 100755
--- a/modifyrepo.py
+++ b/modifyrepo.py
@@ -60,6 +60,9 @@ class RepoMetadata:
         """ Get mdtype from existing mdtype or from a mdname. """
         if mdtype:
             return mdtype
+        mdname = os.path.basename(mdname)
+        if re.match(r'[0-9a-f]{32,}-', mdname):
+            mdname = mdname.split('-', 1)[1]
         return mdname.split('.')[0]
 
     def _print_repodata(self, repodata):
@@ -80,7 +83,8 @@ class RepoMetadata:
     def _remove_repodata_file(self, repodata):
         """ Remove a file specified in repodata location """
         try:
-            os.remove(repodata.location[1])
+            fname = os.path.basename(repodata.location[1])
+            os.remove(os.path.join(self.repodir, fname))
         except OSError, ex:
             if ex.errno != 2:
                 # continue on a missing file
@@ -239,7 +243,7 @@ def main(args):
     # remove
     if opts.remove:
         try:
-            repomd.remove(metadata)
+            repomd.remove(metadata, mdtype=opts.mdtype)
         except MDError, ex:
             print "Could not remove metadata: %s" % (metadata, str(ex))
             return 1
-- 
1.7.11.7