[pacman-dev] [PATCH 2/2] pactest: fix gensync

Xavier Chantry chantry.xavier at gmail.com
Sun Oct 10 19:05:04 EDT 2010


gensync generated a sync.db file with PKGINFO
syntax, this is not quite what pacman expects.

Also the file was only added to the Server path :
root/var/pub/sync/sync.db
but it was not available in the normal sync db path :
root/var/lib/pacman/sync/sync.db

change gensync() to generate var/lib/pacman/sync/sync.db and then copy
it to var/pub/sync/sync.db (this is used by sync200 -Sy test)
---
 test/pacman/pmdb.py   |   30 +++++++++++++-----------------
 test/pacman/pmtest.py |   12 +++++++-----
 test/pacman/util.py   |    1 +
 3 files changed, 21 insertions(+), 22 deletions(-)

Allan will be happy.. hopefully :)

diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py
index 11083db..efd0cc2 100755
--- a/test/pacman/pmdb.py
+++ b/test/pacman/pmdb.py
@@ -81,11 +81,15 @@ class pmdb:
     """Database object
     """
 
-    def __init__(self, treename, dbdir):
+    def __init__(self, treename, root):
         self.treename = treename
-        self.dbdir = dbdir
         self.pkgs = []
         self.option = {}
+        if self.treename == "local":
+            self.dbdir = os.path.join(root, PM_DBPATH, treename)
+        else:
+            self.dbdir = os.path.join(root, PM_SYNCDBPATH, treename)
+            self.dbfile = os.path.join(root, PM_SYNCDBPATH, treename + ".db")
 
     def __str__(self):
         return "%s" % self.treename
@@ -101,7 +105,7 @@ def db_read(self, name):
         """
         """
 
-        path = os.path.join(self.dbdir, self.treename)
+        path = self.dbdir
         if not os.path.isdir(path):
             return None
 
@@ -227,10 +231,7 @@ def db_write(self, pkg):
         """
         """
 
-        if self.treename == "local":
-            path = os.path.join(self.dbdir, self.treename, pkg.fullname())
-        else:
-            path = os.path.join(self.dbdir, "sync", self.treename, pkg.fullname())
+        path = os.path.join(self.dbdir, pkg.fullname())
         mkdir(path)
 
         # desc
@@ -331,27 +332,22 @@ def db_write(self, pkg):
                 pkg.checksum["install"] = getmd5sum(filename)
                 pkg.mtime["install"] = getmtime(filename)
 
-    def gensync(self, path):
+    def gensync(self):
         """
         """
 
+        if not self.dbfile:
+            return
         curdir = os.getcwd()
-        tmpdir = tempfile.mkdtemp()
-        os.chdir(tmpdir)
-
-        for pkg in self.pkgs:
-            mkdescfile(pkg.fullname(), pkg)
+        os.chdir(self.dbdir)
 
         # Generate database archive
-        mkdir(path)
-        archive = os.path.join(path, "%s.db" % (self.treename))
-        tar = tarfile.open(archive, "w:gz")
+        tar = tarfile.open(self.dbfile, "w:gz")
         for i in os.listdir("."):
             tar.add(i)
         tar.close()
 
         os.chdir(curdir)
-        shutil.rmtree(tmpdir)
 
     def ispkgmodified(self, pkg):
         """
diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py
index 5c8881c..c476929 100755
--- a/test/pacman/pmtest.py
+++ b/test/pacman/pmtest.py
@@ -47,7 +47,7 @@ def addpkg2db(self, treename, pkg):
         """
         """
         if not treename in self.db:
-            self.db[treename] = pmdb.pmdb(treename, os.path.join(self.root, PM_DBPATH))
+            self.db[treename] = pmdb.pmdb(treename, self.root)
         self.db[treename].pkgs.append(pkg)
 
     def addpkg(self, pkg):
@@ -73,7 +73,7 @@ def load(self):
         self.args = ""
         self.retcode = 0
         self.db = {
-            "local": pmdb.pmdb("local", os.path.join(self.root, PM_DBPATH))
+            "local": pmdb.pmdb("local", self.root)
         }
         self.localpkgs = []
         self.filesystem = []
@@ -152,9 +152,11 @@ def generate(self):
         vprint("    Creating sync database archives")
         for key, value in self.db.iteritems():
             if key == "local": continue
-            archive = value.treename + ".db"
-            vprint("\t" + os.path.join(SYNCREPO, archive))
-            value.gensync(os.path.join(syncdir, value.treename))
+            vprint("\t" + value.treename)
+            value.gensync()
+            serverpath = os.path.join(syncdir, value.treename)
+            mkdir(serverpath)
+            shutil.copy(value.dbfile, serverpath)
 
         # Filesystem
         vprint("    Populating file system")
diff --git a/test/pacman/util.py b/test/pacman/util.py
index 657230e..802f22e 100755
--- a/test/pacman/util.py
+++ b/test/pacman/util.py
@@ -25,6 +25,7 @@
 # ALPM
 PM_ROOT     = "/"
 PM_DBPATH   = "var/lib/pacman"
+PM_SYNCDBPATH = "var/lib/pacman/sync"
 PM_LOCK     = "var/lib/pacman/db.lck"
 PM_CACHEDIR = "var/cache/pacman/pkg"
 PM_EXT_PKG  = ".pkg.tar.gz"
-- 
1.7.3.1



More information about the pacman-dev mailing list