SF.net SVN: gar:[23245] csw/mgar/gar/v2/src/catalog-release-to-disk.go

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Mar 17 17:50:53 CET 2014


Revision: 23245
          http://sourceforge.net/p/gar/code/23245
Author:   wahwah
Date:     2014-03-17 16:50:53 +0000 (Mon, 17 Mar 2014)
Log Message:
-----------
cat-gen: rm "catalog" and "descriptions" on empty

When the catalog is empty, all .pkg and .pkg.gz files are unlinked. To
accompany that, let's delete the "catalog" and "description" files.
Therefore, an empty catalog is represented by a missing catalog and
description files.

This is compatible with chkcat behavior which throws an error on a
signed but empty catalog file: no file to check, no error.

Modified Paths:
--------------
    csw/mgar/gar/v2/src/catalog-release-to-disk.go

Modified: csw/mgar/gar/v2/src/catalog-release-to-disk.go
===================================================================
--- csw/mgar/gar/v2/src/catalog-release-to-disk.go	2014-03-17 02:39:56 UTC (rev 23244)
+++ csw/mgar/gar/v2/src/catalog-release-to-disk.go	2014-03-17 16:50:53 UTC (rev 23245)
@@ -683,7 +683,35 @@
                               cws CatalogWithSpec) {
   log.Printf("GenerateCatalogIndexFile(%v, %v)\n", catalog_root, cws.spec)
   catalog_file_path := FormatCatalogFilePath(catalog_root, cws.spec, "catalog")
+  desc_file_path := FormatCatalogFilePath(catalog_root, cws.spec, "descriptions")
 
+  defer func() {
+    // If there's a "catalog.gz" here, remove it. It will be recreated later by
+    // the shell script which signs catalogs.
+    gzip_catalog := catalog_file_path + ".gz";
+    if err := os.Remove(gzip_catalog); err != nil {
+      log.Println("Not removed", gzip_catalog, "error was", err)
+    } else {
+      log.Println(gzip_catalog, "was removed")
+    }
+  }()
+
+  // If there are no files in the catalog, simply remove the catalog files.
+  if len(cws.pkgs) <= 0 {
+    for _, filename := range []string{catalog_file_path, desc_file_path} {
+      // If the files are missing, that's okay
+      if err := os.Remove(filename); err != nil {
+        if err != syscall.ENOENT {
+          log.Println("Could not remove", filename, "error:", err)
+        }
+      } else {
+        log.Println("Removed", filename, "because the", cws.spec,
+                    "catalog is empty")
+      }
+    }
+    return
+  }
+
   var catbuf *bufio.Writer
   var descbuf *bufio.Writer
 
@@ -697,7 +725,6 @@
     catbuf = bufio.NewWriter(catalog_fd)
     defer catbuf.Flush()
 
-    desc_file_path := FormatCatalogFilePath(catalog_root, cws.spec, "descriptions")
     desc_fd, err := os.Create(desc_file_path)
     if err != nil {
       log.Fatalln("Could not open", desc_file_path, "for writing:", err)

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