Differentiate between IO-errors and non-package "error" in rpmgi foo
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Sep 2010 10:31:25 +0000 (13:31 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 8 Sep 2010 10:31:25 +0000 (13:31 +0300)
- rpmgiLoadReadHeader() tested errno, but this isn't realiable:
  rpmgiReadHeader() didn't differentiate between IO and other errors
  properly so errno would be tested even when no errors (other than
  not being a header) were present. This could be pretty much whatever
  when no IO errors occurred in rpmgiReadHeader() but the file just
  wasn't a header. With libio errno was typically EBADF, causing the
  remaining code to execute, but without libio this happened to be
  ENOENTRY, causing a silent failure on manifest query.
- This junk needs to die, really.

lib/rpmgi.c

index 9b763ec..fa9ed75 100644 (file)
@@ -76,9 +76,10 @@ static rpmRC rpmgiLoadManifest(rpmgi gi, const char * path)
  * Return header from package.
  * @param gi           generalized iterator
  * @param path         file path
- * @return             header (NULL on failure)
+ * @retval hdrp                header (NULL on failure)
+ * @return             1 if path could be opened, 0 if not
  */
-static Header rpmgiReadHeader(rpmgi gi, const char * path)
+static int rpmgiReadHeader(rpmgi gi, const char * path, Header * hdrp)
 {
     FD_t fd = rpmgiOpen(path, "r.ufdio");
     Header h = NULL;
@@ -103,7 +104,8 @@ static Header rpmgiReadHeader(rpmgi gi, const char * path)
        }
     }
 
-    return h;
+    *hdrp = h;
+    return (fd != NULL);
 }
 
 /**
@@ -120,13 +122,10 @@ static Header rpmgiLoadReadHeader(rpmgi gi)
     if (gi->argv != NULL && gi->argv[gi->i] != NULL)
     do {
        char * fn = gi->argv[gi->i];
-       h = rpmgiReadHeader(gi, fn);
+       int rc = rpmgiReadHeader(gi, fn, &h);
 
-       if (h != NULL || gi->flags & RPMGI_NOMANIFEST)
-           break;
-       if (errno == ENOENT) {
+       if (h != NULL || (gi->flags & RPMGI_NOMANIFEST) || rc == 0)
            break;
-       }
 
        /* Not a header, so try for a manifest. */
        gi->argv[gi->i] = NULL;         /* Mark the insertion point */