From: Tomas Mlcoch Date: Fri, 27 Jan 2012 08:05:16 +0000 (+0100) Subject: Add file stat struct param for xml_from_package_file() X-Git-Tag: upstream/0.2.1~576 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c5738ab64490256eaa1a09676a18f5a9cfb7fa8;p=services%2Fcreaterepo_c.git Add file stat struct param for xml_from_package_file() --- 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__ */