[csw-devel] SF.net SVN: gar:[12139] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Dec 30 14:58:28 CET 2010


Revision: 12139
          http://gar.svn.sourceforge.net/gar/?rev=12139&view=rev
Author:   wahwah
Date:     2010-12-30 13:58:28 +0000 (Thu, 30 Dec 2010)

Log Message:
-----------
checkpkg: Don't destroy srv4_file_stats objects

It leads to issues: When a srv4_file_stats object is destroyed, it leads to
inconsistencies in catalogs.  Instead, preserve the old object (and its ID)
and update the contsnts.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/package_stats.py
    csw/mgar/gar/v2/lib/python/pkgdb.py

Modified: csw/mgar/gar/v2/lib/python/package_stats.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_stats.py	2010-12-30 13:57:55 UTC (rev 12138)
+++ csw/mgar/gar/v2/lib/python/package_stats.py	2010-12-30 13:58:28 UTC (rev 12139)
@@ -100,11 +100,9 @@
     if not pkg_stats:
       return False
     if pkg_stats.stats_version != PACKAGE_STATS_VERSION:
-      pkg_stats.DeleteAllDependentObjects()
-      pkg_stats.destroySelf()
+      return False
     elif pkg_stats.data_obj is None:
-      pkg_stats.DeleteAllDependentObjects()
-      pkg_stats.destroySelf()
+      return False
     else:
       return True
     return False
@@ -269,35 +267,59 @@
         rev = parsed_basename["revision_info"]["REV"]
     # If the object already exists in the database, delete it.
     md5_sum = pkg_stats["basic_stats"]["md5_sum"]
+    db_pkg_stats = None
     try:
       db_pkg_stats = m.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
-      logging.debug("Destroying %s before saving it again", db_pkg_stats)
+      logging.debug("Cleaning %s before saving it again", db_pkg_stats)
       db_pkg_stats.DeleteAllDependentObjects()
-      db_pkg_stats.destroySelf()
     except sqlobject.main.SQLObjectNotFound, e:
       logging.debug("Package %s not present in the db, proceeding with insert.")
       pass
     # Creating the object in the database.
     data_obj = m.Srv4FileStatsBlob(
         pickle=cPickle.dumps(pkg_stats))
-    db_pkg_stats = m.Srv4FileStats(
-        arch=arch,
-        basename=pkg_stats["basic_stats"]["pkg_basename"],
-        catalogname=pkg_stats["basic_stats"]["catalogname"],
-        data_obj=data_obj,
-        use_to_generate_catalogs=True,
-        filename_arch=filename_arch,
-        latest=True,
-        maintainer=maintainer,
-        md5_sum=pkg_stats["basic_stats"]["md5_sum"],
-        size=pkg_stats["basic_stats"]["size"],
-        mtime=pkg_stats["mtime"],
-        os_rel=os_rel,
-        pkginst=pkginst,
-        registered=register,
-        rev=rev,
-        stats_version=PACKAGE_STATS_VERSION,
-        version_string=parsed_basename["full_version_string"])
+    if db_pkg_stats:
+      # If the database row exists already, update it.
+      #
+      # Assigning properties one by one isn't pretty, but I don't have
+      # a better way of doing it.  Ideally, both creation and update would be
+      # driven by the same data structure.
+      db_pkg_stats.arch = arch
+      db_pkg_stats.basename = pkg_stats["basic_stats"]["pkg_basename"]
+      db_pkg_stats.catalogname = pkg_stats["basic_stats"]["catalogname"]
+      db_pkg_stats.data_obj = data_obj
+      db_pkg_stats.use_to_generate_catalogs = True
+      db_pkg_stats.filename_arch = filename_arch
+      db_pkg_stats.latest = True
+      db_pkg_stats.maintainer = maintainer
+      db_pkg_stats.md5_sum = pkg_stats["basic_stats"]["md5_sum"]
+      db_pkg_stats.size = pkg_stats["basic_stats"]["size"]
+      db_pkg_stats.mtime = pkg_stats["mtime"]
+      db_pkg_stats.os_rel = os_rel
+      db_pkg_stats.pkginst = pkginst
+      db_pkg_stats.registered = register
+      db_pkg_stats.rev = rev
+      db_pkg_stats.stats_version = PACKAGE_STATS_VERSION
+      db_pkg_stats.version_string = parsed_basename["full_version_string"]
+    else:
+      db_pkg_stats = m.Srv4FileStats(
+          arch=arch,
+          basename=pkg_stats["basic_stats"]["pkg_basename"],
+          catalogname=pkg_stats["basic_stats"]["catalogname"],
+          data_obj=data_obj,
+          use_to_generate_catalogs=True,
+          filename_arch=filename_arch,
+          latest=True,
+          maintainer=maintainer,
+          md5_sum=pkg_stats["basic_stats"]["md5_sum"],
+          size=pkg_stats["basic_stats"]["size"],
+          mtime=pkg_stats["mtime"],
+          os_rel=os_rel,
+          pkginst=pkginst,
+          registered=register,
+          rev=rev,
+          stats_version=PACKAGE_STATS_VERSION,
+          version_string=parsed_basename["full_version_string"])
     # Inserting overrides as rows into the database
     for override_dict in pkg_stats["overrides"]:
       o = m.CheckpkgOverride(srv4_file=db_pkg_stats,

Modified: csw/mgar/gar/v2/lib/python/pkgdb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgdb.py	2010-12-30 13:57:55 UTC (rev 12138)
+++ csw/mgar/gar/v2/lib/python/pkgdb.py	2010-12-30 13:58:28 UTC (rev 12139)
@@ -237,8 +237,15 @@
           m.Srv4FileInCatalog.q.catrel==sqo_catrel))
     db_srv4s_in_cat_by_md5 = {}
     for srv4_in_cat in res:
-      if srv4_in_cat.srv4file.use_to_generate_catalogs:
-        db_srv4s_in_cat_by_md5[srv4_in_cat.srv4file.md5_sum] = srv4_in_cat
+      try:
+        srv4 = srv4_in_cat.srv4file
+        if srv4.use_to_generate_catalogs:
+          db_srv4s_in_cat_by_md5[srv4.md5_sum] = srv4_in_cat
+      except sqlobject.main.SQLObjectNotFound, e:
+        logging.warning("Could not retrieve a srv4 file from the db: %s", e)
+        # Since the srv4_in_cat object has lost its reference, there's no use
+        # keeping it around.
+        srv4_in_cat.destroySelf()
     disk_md5s = set(cat_entry_by_md5)
     db_md5s = set(db_srv4s_in_cat_by_md5)
     #   - match the md5 sum lists between db and disk


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list