From 80d55f0b15345d2f8893b303731a144e6be402dc Mon Sep 17 00:00:00 2001
From: Jon Disnard <jdisnard@redhat.com>
Date: Jun 06 2015 18:49:40 +0000
Subject: [PATCH 1/2] New class MetadataOld_c to enable createrepo_c


Signed-off-by: Jon Disnard <jdisnard@redhat.com>

---

diff --git a/mash/metadata.py b/mash/metadata.py
index de5050b..72843d8 100644
--- a/mash/metadata.py
+++ b/mash/metadata.py
@@ -235,13 +235,101 @@ class MetadataNew:
             _make_ancient(path, self.conf.excludes, self.previous, self.logger)
 
 
+class MetadataOld_c:
+    def __init__(self, logger):
+        self.args = [ 'createrepo_c', '--update', '-q' ]
+        self.previous = None
+        self.logger = logger
+        self.excludes = []
+        self.ancient = False
+
+    def set_ancient(self, ancient):
+        self.ancient = ancient
+
+    def set_cachedir(self, path):
+        self.args.append('-c')
+        self.args.append(path)
+
+    def set_comps(self, comps):
+        self.args.append('-g')
+        self.args.append(comps)
+
+    def set_excludes(self, excludes):
+        self.args.append('-x')
+        self.args.append(excludes)
+        self.excludes.append(excludes)
+
+    def set_database(self, db):
+        self.args.append('-d')
+
+    def set_compress_type(self, compress_type):
+        self.args.append('--compress-type')
+        self.args.append(compress_type)
+
+    def set_hash(self, hashtype):
+        # Sorry, can't do that here.
+        #pass
+        
+        ## YES, we can do that here.
+        self.args.append('--checksum')
+        self.args.append(hashtype)
+
+    def set_skipstat(self, skip):
+        if skip:
+            self.args.append('--skip-stat')
+
+    def set_delta(self, deltapaths, max_delta_rpm_size, max_delta_rpm_age, delta_workers):
+        # Sorry, can't do that here.
+        ## We still can not do that here.
+        pass
+
+    def set_previous(self, previous):
+        self.previous = previous
+
+    def set_distro_tags(self, distro_tags):
+        # Sorry, can't do that here.
+        #pass
+        ## YES, we can do that here.
+        self.args.append('--distro')
+        self.args.append(distro_tags)
+
+    def set_content_tags(self, content_tags):
+        # Sorry, can't do that here.
+        #pass
+        ## YES, we can do that here.
+        self.args.append('--content')
+        self.args.append(content_tags)
+
+    def run(self, path):
+        self.args.append(path)
+        if self.previous:
+            try:
+                shutil.copytree("%s/repodata" %(self.previous,), "%s/repodata" % (path,))
+            except OSError:
+                self.logger.error("Couldn't copy repodata from %s" % (self.previous,))
+        pid = os.fork()
+        if not pid:
+            os.execv("/usr/bin/createrepo_c", self.args)
+        else:
+            (p, status) = os.waitpid(pid, 0)
+        if self.ancient:
+            _make_ancient(path, self.excludes, self.previous, self.logger)
+
+
 class Metadata:
 
     def __init__(self, logger):
-        if usenew:
-            self.obj = MetadataNew(logger)
+        if repo_c:
+            if usenew:
+                # For now use the old createcrepo api
+                self.obj = MetadataNew(logger)
+            else:
+                self.obj = MetadataOld_c(logger)
         else:
-            self.obj = MetadataOld(logger)
+            if usenew:
+                self.obj = MetadataNew(logger)
+            else:
+                self.obj = MetadataOld(logger)
 
     def set_ancient(self, ancient):
         self.obj.set_ancient(ancient)

From 4faea8e74198d04055b6a056523ea39fd7c905a6 Mon Sep 17 00:00:00 2001
From: Jon Disnard <jdisnard@redhat.com>
Date: Jun 06 2015 18:53:34 +0000
Subject: [PATCH 2/2] Trivial whitespace fix


Signed-off-by: Jon Disnard <jdisnard@redhat.com>

---

diff --git a/mash/metadata.py b/mash/metadata.py
index 72843d8..0f76e18 100644
--- a/mash/metadata.py
+++ b/mash/metadata.py
@@ -269,7 +269,7 @@ class MetadataOld_c:
     def set_hash(self, hashtype):
         # Sorry, can't do that here.
         #pass
-        
+
         ## YES, we can do that here.
         self.args.append('--checksum')
         self.args.append(hashtype)

