SF.net SVN: gar:[23270] csw/mgar/gar/v2/go/src/opencsw/diskformat

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Mar 23 15:21:08 CET 2014


Revision: 23270
          http://sourceforge.net/p/gar/code/23270
Author:   wahwah
Date:     2014-03-23 14:21:08 +0000 (Sun, 23 Mar 2014)
Log Message:
-----------
cat-gen: Check for catalog with missing deps

This should catch some of the problems we've recently observed.

This change catches problems with the catalog before we generate the catalog.
This way we avoid the problem in which we halt all catalog generation because
of one failed catalog.

Modified Paths:
--------------
    csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go

Added Paths:
-----------
    csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat_test.go

Modified: csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go
===================================================================
--- csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go	2014-03-23 14:21:00 UTC (rev 23269)
+++ csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go	2014-03-23 14:21:08 UTC (rev 23270)
@@ -18,14 +18,15 @@
   "time"
 )
 
-
+// Do not actually perform any operations on disk. Read data and process, but do
+// not write anything.
 var Dry_run bool
 // Keeping Pkgdb_url as a package global variable is probably not the best idea,
 // but let's not refactor without a good plan.
 var Pkgdb_url string
 
 
-// 3 strings that define a specific catalog
+// 3 strings that define a specific catalog, e.g. "unstable sparc 5.10"
 type CatalogSpec struct {
   catrel string
   arch string
@@ -162,6 +163,28 @@
   return cws
 }
 
+// Run sanity checks and return the result. Currently only checks if there are
+// any dependencies on packages absent from the catalog.
+func (cws *CatalogWithSpec) IsSane() bool {
+  catalog_ok := true
+  deps_by_pkginst := make(map[string]PkginstSlice)
+  for _, pkg := range cws.pkgs {
+    deps_by_pkginst[pkg.Pkginst] = pkg.Depends
+  }
+  for _, pkg := range cws.pkgs {
+    for _, dep := range pkg.Depends {
+      if _, ok := deps_by_pkginst[dep]; !ok {
+        log.Printf(
+          "Problem in the catalog: Package %s declares dependency on %s " +
+          "but %s is missing from the %s catalog.", pkg.Pkginst, dep, dep,
+          cws.spec)
+        catalog_ok = false
+      }
+    }
+  }
+  return catalog_ok;
+}
+
 func NewPkgInCatalog(lst []string) (*PkgInCatalog, error) {
   size, err := strconv.ParseUint(lst[5], 10, 64)
   if err != nil {
@@ -255,6 +278,11 @@
   log.Println("Retrieved", catspec, "with", len(pkgs), "packages")
 
   cws := MakeCatalogWithSpec(catspec, pkgs)
+  if !cws.IsSane() {
+    return cws, fmt.Errorf("There are sanity issues with the %s catalog. " +
+                           "Please check the log for more information.",
+                           cws.spec)
+  }
   return cws, nil
 }
 

Added: csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat_test.go
===================================================================
--- csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat_test.go	                        (rev 0)
+++ csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat_test.go	2014-03-23 14:21:08 UTC (rev 23270)
@@ -0,0 +1,54 @@
+package diskformat
+
+import (
+  "testing"
+  "encoding/json"
+)
+
+const small_cat = `
+[
+    {
+        "basename": "common-1.5,REV=2010.12.11-SunOS5.8-sparc-CSW.pkg",
+        "catalogname": "common",
+        "category": "none",
+        "deps": "none",
+        "desc": "common - common files and dirs for CSW packages",
+        "i_deps": "none",
+        "md5_sum": "f83ab71194e67e04d1eee5d8db094011",
+        "pkgname": "CSWcommon",
+        "size": 23040,
+        "version": "1.5,REV=2010.12.11"
+    },
+    {
+        "basename": "dash-0.5.7,REV=2012.04.17-SunOS5.9-sparc-CSW.pkg.gz",
+        "catalogname": "dash",
+        "category": "none",
+        "deps": "CSWcommon",
+        "desc": "dash - POSIX-compliant implementation of /bin/sh that aims to be as small as possible",
+        "i_deps": "none",
+        "md5_sum": "d1efb8957f35591ba3cf49fba2f41d21",
+        "pkgname": "CSWdash",
+        "size": 75821,
+        "version": "0.5.7,REV=2012.04.17"
+    }
+]`
+
+func TestVanilla(t *testing.T) {
+  c := Catalog{}
+  err := json.Unmarshal([]byte(small_cat), &c)
+  if err != nil { t.Error(err); t.FailNow() }
+  spec := CatalogSpec{"fake", "sparc", "5.10"}
+  cws := CatalogWithSpec{spec, c}
+  if !cws.IsSane() { t.Error("This catalog should be OK") }
+}
+
+func TestMissing(t *testing.T) {
+  c := Catalog{}
+  err := json.Unmarshal([]byte(small_cat), &c)
+  c = c[1:]
+  spec := CatalogSpec{"fake", "sparc", "5.10"}
+  cws := CatalogWithSpec{spec, c}
+  // t.Log("c:", c)
+  if err != nil { t.Error(err); t.FailNow() }
+  if cws.IsSane() { t.Error("This catalog is missing a dependency") }
+}

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