Add file stat struct param for xml_from_package_file()
authorTomas Mlcoch <tmlcoch@redhat.com>
Fri, 27 Jan 2012 08:05:16 +0000 (09:05 +0100)
committerTomas Mlcoch <tmlcoch@redhat.com>
Fri, 27 Jan 2012 08:05:16 +0000 (09:05 +0100)
ctests/parsepkg_test_01.c
parsepkg.c
parsepkg.h

index 42d1926..3585867 100644 (file)
@@ -11,13 +11,13 @@ int main() {
 
     int x;
     for (x=0; x<1000; x++) {
-        res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 4);
+        res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 5, NULL);
         free(res.primary);
         free(res.filelists);
         free(res.other);
     }
 
-    res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 4);
+    res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 5, NULL);
 
     free_package_parser();
 
index 3a31620..122cc9d 100644 (file)
@@ -34,7 +34,8 @@ void free_package_parser()
 
 
 struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checksum_type,
-                const char *location_href, const char *location_base, int changelog_limit)
+                const char *location_href, const char *location_base, int changelog_limit,
+                struct stat *stat_buf)
 {
     struct XmlStruct result;
     result.primary   = NULL;
@@ -71,13 +72,21 @@ struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checks
 
     // Get file stat
 
-    struct stat stat_buf;
-    if (stat(filename, &stat_buf) == -1) {
-        perror("stat");
-        return result;
+    gint64 mtime;
+    gint64 size;
+
+    if (!stat_buf) {
+        struct stat stat_buf_own;
+        if (stat(filename, &stat_buf_own) == -1) {
+            perror("stat");
+            return result;
+        }
+        mtime  = stat_buf_own.st_mtime;
+        size   = stat_buf_own.st_size;
+    } else {
+        mtime  = stat_buf->st_mtime;
+        size   = stat_buf->st_size;
     }
-    gint64 mtime  = stat_buf.st_mtime;
-    gint64 size   = stat_buf.st_size;
 
     // Compute checksum
 
index 726f249..4345737 100644 (file)
@@ -17,8 +17,12 @@ extern short initialized;
 void init_package_parser();
 void free_package_parser();
 
+
+// TODO: swig map for struct stat stat_buf
+
+// stat_buf can be NULL
 struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checksum_type,
                         const char *location_href, const char *location_base,
-                        int changelog_limit);
+                        int changelog_limit, struct stat *stat_buf);
 
 #endif /* __PARSEPKG__ */