From 4e77dbaaa852b1e60f119e0dc1c175c7f333d925 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 13 Oct 2023 14:07:58 +0200 Subject: allow retrieval of hardlink content --- package.xml | 1 + rpminfo.c | 22 ++++++++++++++++------ tests/014-stream.phpt | 6 ++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package.xml b/package.xml index 0883ab2..7ec6979 100644 --- a/package.xml +++ b/package.xml @@ -25,6 +25,7 @@ Documentation: https://www.php.net/rpminfo PHP-3.01 - fix stack smashing on 32-bit +- allow retrieval of hardlink content diff --git a/rpminfo.c b/rpminfo.c index 7eb992e..d94ac72 100644 --- a/rpminfo.c +++ b/rpminfo.c @@ -639,7 +639,7 @@ const php_stream_ops php_stream_rpmio_ops = { NULL /* set_option */ }; -static struct php_rpm_stream_data_t *php_stream_rpm_finder(const char *path) +static struct php_rpm_stream_data_t *php_stream_rpm_finder(const char *path, int want_content) { size_t path_len; zend_string *file_basename; @@ -700,16 +700,26 @@ static struct php_rpm_stream_data_t *php_stream_rpm_finder(const char *path) } files = rpmfilesNew(NULL, h, 0, RPMFI_KEEPHEADER); - fi = rpmfiNewArchiveReader(gzdi, files, RPMFI_ITER_READ_ARCHIVE_CONTENT_FIRST); + fi = rpmfiNewArchiveReader(gzdi, files, RPMFI_ITER_READ_ARCHIVE); while((rc = rpmfiNext(fi)) >=0) { const char *fn = rpmfiFN(fi); /* - printf("Name=%s, Size=%d, N=%d, mode=%d, reg=%d, content=%d\n", fn, + printf("Name=%s, Size=%d, N=%d, mode=%d, reg=%d, content=%d, rdev=%d, inode=%d\n", fn, (int)rpmfiFSize(fi), (int)rpmfiFNlink(fi), (int)rpmfiFMode(fi), - (int)S_ISREG(rpmfiFMode(fi)), (int)rpmfiArchiveHasContent(fi)); + (int)S_ISREG(rpmfiFMode(fi)), (int)rpmfiArchiveHasContent(fi), + (int)rpmfiFRdev(fi), (int)rpmfiFInode(fi)); */ if (!strcmp(fn, fragment)) { + if (want_content && S_ISREG(rpmfiFMode(fi)) && !rpmfiArchiveHasContent(fi)) { + rpm_rdev_t rdev = rpmfiFRdev(fi); + rpm_ino_t inode = rpmfiFInode(fi); + while((rc = rpmfiNext(fi)) >=0) { + if (rdev == rpmfiFRdev(fi) && inode == rpmfiFInode(fi) && rpmfiArchiveHasContent(fi)) { + break; + } + } + } break; } } @@ -742,7 +752,7 @@ php_stream *php_stream_rpm_opener(php_stream_wrapper *wrapper, if (mode[0] != 'r') { return NULL; } - self = php_stream_rpm_finder(path); + self = php_stream_rpm_finder(path, 1); if (self) { if (opened_path) { *opened_path = zend_string_init(path, strlen(path), 0); @@ -763,7 +773,7 @@ static int php_stream_rpm_stat(php_stream_wrapper *wrapper, const char *url, int struct php_rpm_stream_data_t *self; int rc = -1; - self = php_stream_rpm_finder(url); + self = php_stream_rpm_finder(url, 0); if (self) { struct stat s[2]; // librpm may use different size (32-bit) rc = rpmfiStat(self->fi, 0, s); diff --git a/tests/014-stream.phpt b/tests/014-stream.phpt index 46d6b66..f084326 100644 --- a/tests/014-stream.phpt +++ b/tests/014-stream.phpt @@ -9,6 +9,8 @@ if (version_compare(RPMVERSION, '4.13', 'lt')) print("skip librpm is older than @@ -63,6 +67,8 @@ string(18) "12:24:27 CEST 2023" bool(true) + stream string(29) "Fri Oct 13 12:24:27 CEST 2023" +string(7) "content" +string(7) "content" Warning: file_get_contents(%s/bidon.rpm#/usr/share/doc/bidon/TODO): Failed to open stream: operation failed in %s on line %d bool(false) -- cgit