Skip to content

Commit ee46324

Browse files
committed
Support libarchive < 3.5.0
1 parent f96397e commit ee46324

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

libarchive.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ static void arch_obj_setup_support(arch_object *arch_obj)
286286
if (arch_obj->filters == NULL) {
287287
archive_read_support_filter_all(arch_obj->archive);
288288
} else {
289+
#if ARCHIVE_VERSION_NUMBER >= 3005000
289290
for (uint32_t i = 0; i < arch_obj->filters_count; i++) {
290291
archive_read_support_filter_by_code(arch_obj->archive, arch_obj->filters[i]);
291292
}
293+
#else
294+
archive_read_support_filter_all(arch_obj->archive);
295+
#endif
292296
}
293297
if (arch_obj->formats == NULL) {
294298
archive_read_support_format_all(arch_obj->archive);
@@ -455,6 +459,11 @@ PHP_METHOD(libarchive_Archive, supportFilters)
455459
"Cannot change filter after archive has been opened", -1);
456460
return;
457461
}
462+
#if ARCHIVE_VERSION_NUMBER < 3005000
463+
php_error_docref(NULL, E_WARNING,
464+
"supportFilters() requires libarchive >= 3.5.0; all filters will be enabled");
465+
RETURN_THIS();
466+
#endif
458467
efree(arch_obj->filters);
459468
arch_obj->filters = safe_emalloc(num_args, sizeof(int), 0);
460469
arch_obj->filters_count = num_args;

libarchive.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace libarchive {
66

7+
/** @var int
8+
* @cvalue ARCHIVE_VERSION_NUMBER */ const LIBARCHIVE_VERSION_ID = UNKNOWN;
9+
710
/** @var int
811
* @cvalue ARCHIVE_FILTER_NONE */ const FILTER_NONE = UNKNOWN;
912
/** @var int

libarchive_arginfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static const zend_function_entry class_libarchive_Archive_methods[] = {
7373

7474
static void register_libarchive_symbols(int module_number)
7575
{
76+
REGISTER_LONG_CONSTANT("libarchive\\LIBARCHIVE_VERSION_ID", ARCHIVE_VERSION_NUMBER, CONST_PERSISTENT);
7677
REGISTER_LONG_CONSTANT("libarchive\\FILTER_NONE", ARCHIVE_FILTER_NONE, CONST_PERSISTENT);
7778
REGISTER_LONG_CONSTANT("libarchive\\FILTER_GZIP", ARCHIVE_FILTER_GZIP, CONST_PERSISTENT);
7879
REGISTER_LONG_CONSTANT("libarchive\\FILTER_BZIP2", ARCHIVE_FILTER_BZIP2, CONST_PERSISTENT);

tests/support-formats-filters.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
--TEST--
22
supportFormats() and supportFilters() restrict archive format and filter detection
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('archive')) die('skip archive extension not loaded');
6+
if (\libarchive\LIBARCHIVE_VERSION_ID < 3005000) die('skip requires libarchive >= 3.5.0');
7+
?>
38
--FILE--
49
<?php
510

0 commit comments

Comments
 (0)