From 0c5738ab64490256eaa1a09676a18f5a9cfb7fa8 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Fri, 27 Jan 2012 09:05:16 +0100 Subject: [PATCH] Add file stat struct param for xml_from_package_file() --- ctests/parsepkg_test_01.c | 4 ++-- parsepkg.c | 23 ++++++++++++++++------- parsepkg.h | 6 +++++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ctests/parsepkg_test_01.c b/ctests/parsepkg_test_01.c index 42d1926..3585867 100644 --- a/ctests/parsepkg_test_01.c +++ b/ctests/parsepkg_test_01.c @@ -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(); diff --git a/parsepkg.c b/parsepkg.c index 3a31620..122cc9d 100644 --- a/parsepkg.c +++ b/parsepkg.c @@ -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 diff --git a/parsepkg.h b/parsepkg.h index 726f249..4345737 100644 --- a/parsepkg.h +++ b/parsepkg.h @@ -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__ */ -- 2.7.4