diff options
author | Remi Collet <remi@remirepo.net> | 2023-10-13 14:07:58 +0200 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2023-10-13 14:07:58 +0200 |
commit | 4e77dbaaa852b1e60f119e0dc1c175c7f333d925 (patch) | |
tree | 769701084c841f81c2e1816235ce238a5b7ff0be | |
parent | 2b84fa512895a69d9a7f85f3b9fc1297bfb53556 (diff) |
allow retrieval of hardlink content
-rw-r--r-- | package.xml | 1 | ||||
-rw-r--r-- | rpminfo.c | 22 | ||||
-rw-r--r-- | 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 <license uri="https://www.php.net/license/3_01.txt" filesource="LICENSE">PHP-3.01</license> <notes> - fix stack smashing on 32-bit +- allow retrieval of hardlink content </notes> <contents> <dir name="/"> @@ -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 <?php $d = "rpm://" . __DIR__ . "/bidon.rpm#/usr/share/doc/bidon"; $n = "rpm://" . __DIR__ . "/bidon.rpm#/usr/share/doc/bidon/README"; +$foo = "rpm://" . __DIR__ . "/bidon.rpm#/etc/foo.conf"; +$bar = "rpm://" . __DIR__ . "/bidon.rpm#/etc/bar.conf"; echo "+ wrapper\n"; var_dump(in_array('rpm', stream_get_wrappers())); @@ -33,6 +35,8 @@ fclose($f); echo "+ stream\n"; var_dump(trim(file_get_contents($n))); +var_dump(trim(file_get_contents($foo))); +var_dump(trim(file_get_contents($bar))); var_dump(file_get_contents(str_replace('README', 'TODO', $n))); ?> @@ -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) |