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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Jun 29 00:51:08 CEST 2010


Revision: 10380
          http://gar.svn.sourceforge.net/gar/?rev=10380&view=rev
Author:   wahwah
Date:     2010-06-28 22:51:08 +0000 (Mon, 28 Jun 2010)

Log Message:
-----------
mGAR v2: checkpkg, file conflict detection within the set under test

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/package_checks.py
    csw/mgar/gar/v2/lib/python/package_checks_test.py

Modified: csw/mgar/gar/v2/lib/python/package_checks.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks.py	2010-06-28 22:06:42 UTC (rev 10379)
+++ csw/mgar/gar/v2/lib/python/package_checks.py	2010-06-28 22:51:08 UTC (rev 10380)
@@ -718,9 +718,32 @@
             % (ldd_elem["symbol"], ldd_elem["path"]))
 
 
-def SetCheckFileCollissions(pkgs_data, error_mgr, logger, messenger):
+def SetCheckFileConflicts(pkgs_data, error_mgr, logger, messenger):
+  """Throw an error if two packages contain the same file.
+
+  Directories don't count.  The strategy is to create an in-memory index of
+  packages by filename.
+  """
+  pkgs_by_path = {}
+  # File types are described at:
+  # http://docs.sun.com/app/docs/doc/816-5174/pkgmap-4?l=en&n=1&a=view
+  file_types = set(["f", "l", "s", "p", "e"])
   for pkg_data in pkgs_data:
-    pass
+    pkgname = pkg_data["basic_stats"]["pkgname"]
+    for pkgmap_entry in pkg_data["pkgmap"]:
+      if pkgmap_entry["type"] in file_types:
+        if pkgmap_entry["path"] not in pkgs_by_path:
+          pkgs_by_path[pkgmap_entry["path"]] = set()
+        pkgs_by_path[pkgmap_entry["path"]].add(pkgname)
+  # Traversing the data structure
+  for file_path in pkgs_by_path:
+    if len(pkgs_by_path[file_path]) > 1:
+      pkgnames = sorted(pkgs_by_path[file_path])
+      for pkgname in pkgnames:
+        error_mgr.ReportError(
+            pkgname,
+            'file-conflict',
+            '%s %s' % (file_path, " ".join(pkgnames)))
 
 
 def CheckPythonPackageName(pkg_data, error_mgr, logger, messenger):

Modified: csw/mgar/gar/v2/lib/python/package_checks_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/package_checks_test.py	2010-06-28 22:06:42 UTC (rev 10379)
+++ csw/mgar/gar/v2/lib/python/package_checks_test.py	2010-06-28 22:51:08 UTC (rev 10380)
@@ -656,5 +656,47 @@
         'or is not allowed for other reasons.')
 
 
+class TestConflictingFiles(CheckpkgUnitTestHelper,
+                           unittest.TestCase):
+  """Throw an error if there's a conflicting file in the package set."""
+  FUNCTION_NAME = 'SetCheckFileConflicts'
+  # Contains only necessary bits.  The data listed in full.
+  CSWbar_DATA = {
+        'basic_stats': {'catalogname': 'bar',
+                        'pkgname': 'CSWbar',
+                        'stats_version': 1},
+        'binaries_dump_info': [],
+        'depends': tuple(),
+        'isalist': [],
+        'pkgmap': [
+          {
+            "type": "f",
+            "path": "/opt/csw/share/foo",
+          }
+        ],
+  }
+  # This one has a conflicting file, this time it's a link, for a change.
+  CSWfoo_DATA = {
+        'basic_stats': {'catalogname': 'foo',
+                        'pkgname': 'CSWfoo',
+                        'stats_version': 1},
+        'binaries_dump_info': [],
+        'depends': tuple(),
+        'isalist': [],
+        'pkgmap': [
+          {
+            "type": "l",
+            "path": "/opt/csw/share/foo",
+          }
+        ],
+  }
+  def CheckpkgTest(self):
+    self.error_mgr_mock.ReportError(
+        'CSWbar', 'file-conflict', '/opt/csw/share/foo CSWbar CSWfoo')
+    self.error_mgr_mock.ReportError(
+        'CSWfoo', 'file-conflict', '/opt/csw/share/foo CSWbar CSWfoo')
+    self.pkg_data = [self.CSWbar_DATA, self.CSWfoo_DATA]
+
+
 if __name__ == '__main__':
   unittest.main()


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