diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | ext/zip/config.m4 | 9 | ||||
-rw-r--r-- | ext/zip/php_zip.c | 65 | ||||
-rw-r--r-- | ext/zip/php_zip.h | 2 | ||||
-rw-r--r-- | ext/zip/php_zip.stub.php | 6 | ||||
-rw-r--r-- | ext/zip/php_zip_arginfo.h | 12 | ||||
-rw-r--r-- | ext/zip/tests/oo_setmtime.phpt | 76 |
7 files changed, 170 insertions, 1 deletions
@@ -118,5 +118,6 @@ PHP NEWS - Zip: . Fixed bug #72374 (remove_path strips first char of filename). (tyage) + . Add ZipArchive::setMtimeName and ZipArchive::setMtimeIndex methods <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/ext/zip/config.m4 b/ext/zip/config.m4 index 0b151b7f2a..669adb6b9a 100644 --- a/ext/zip/config.m4 +++ b/ext/zip/config.m4 @@ -9,6 +9,15 @@ if test "$PHP_ZIP" != "no"; then PHP_EVAL_INCLINE($LIBZIP_CFLAGS) PHP_EVAL_LIBLINE($LIBZIP_LIBS, ZIP_SHARED_LIBADD) + PHP_CHECK_LIBRARY(zip, zip_file_set_mtime, + [ + AC_DEFINE(HAVE_SET_MTIME, 1, [Libzip >= 1.0.0 with zip_file_set_mtime]) + ], [ + AC_MSG_WARN(Libzip >= 1.0.0 needed for setting mtime) + ], [ + -L$LIBZIP_LIBDIR + ]) + PHP_CHECK_LIBRARY(zip, zip_file_set_encryption, [ AC_DEFINE(HAVE_ENCRYPTION, 1, [Libzip >= 1.2.0 with encryption support]) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index d39ad316ae..1218d707f0 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -2301,6 +2301,67 @@ static ZIPARCHIVE_METHOD(setCompressionIndex) } /* }}} */ +#ifdef HAVE_SET_MTIME +/* {{{ proto bool ZipArchive::setMtimeName(string name, int timestamp[, int flags]) +Set the modification time of a file in zip, using its name */ +static ZIPARCHIVE_METHOD(setMtimeName) + { + struct zip *intern; + zval *this = ZEND_THIS; + size_t name_len; + char *name; + zip_int64_t idx; + zend_long mtime, flags = 0; + + ZIP_FROM_OBJECT(intern, this); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l", + &name, &name_len, &mtime, &flags) == FAILURE) { + return; + } + + if (name_len < 1) { + php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); + } + + idx = zip_name_locate(intern, name, 0); + if (idx < 0) { + RETURN_FALSE; + } + + if (zip_file_set_mtime(intern, (zip_uint64_t)idx, + (time_t)mtime, (zip_uint32_t)flags) != 0) { + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto bool ZipArchive::setMtimeIndex(int index, int timestamp[, int flags]) +Set the modification time of a file in zip, using its index */ +static ZIPARCHIVE_METHOD(setMtimeIndex) +{ + struct zip *intern; + zval *this = ZEND_THIS; + zend_long index; + zend_long mtime, flags = 0; + + ZIP_FROM_OBJECT(intern, this); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l", + &index, &mtime, &flags) == FAILURE) { + return; + } + + if (zip_file_set_mtime(intern, (zip_uint64_t)index, + (time_t)mtime, (zip_uint32_t)flags) != 0) { + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ +#endif + /* {{{ proto bool ZipArchive::deleteIndex(int index) Delete a file using its index */ static ZIPARCHIVE_METHOD(deleteIndex) @@ -2755,6 +2816,10 @@ static const zend_function_entry zip_class_functions[] = { #endif ZIPARCHIVE_ME(setCompressionName, arginfo_class_ZipArchive_setCompressionName, ZEND_ACC_PUBLIC) ZIPARCHIVE_ME(setCompressionIndex, arginfo_class_ZipArchive_setCompressionIndex, ZEND_ACC_PUBLIC) +#ifdef HAVE_SET_MTIME + ZIPARCHIVE_ME(setMtimeName, arginfo_class_ZipArchive_setMtimeName, ZEND_ACC_PUBLIC) + ZIPARCHIVE_ME(setMtimeIndex, arginfo_class_ZipArchive_setMtimeIndex, ZEND_ACC_PUBLIC) +#endif #ifdef HAVE_ENCRYPTION ZIPARCHIVE_ME(setEncryptionName, arginfo_class_ZipArchive_setEncryptionName, ZEND_ACC_PUBLIC) ZIPARCHIVE_ME(setEncryptionIndex, arginfo_class_ZipArchive_setEncryptionIndex, ZEND_ACC_PUBLIC) diff --git a/ext/zip/php_zip.h b/ext/zip/php_zip.h index f900632e56..d1f46ea4ea 100644 --- a/ext/zip/php_zip.h +++ b/ext/zip/php_zip.h @@ -31,7 +31,7 @@ extern zend_module_entry zip_module_entry; #define ZIP_OVERWRITE ZIP_TRUNCATE #endif -#define PHP_ZIP_VERSION "1.15.6" +#define PHP_ZIP_VERSION "1.16.0" #define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename) diff --git a/ext/zip/php_zip.stub.php b/ext/zip/php_zip.stub.php index e312bfd031..c88d2742ee 100644 --- a/ext/zip/php_zip.stub.php +++ b/ext/zip/php_zip.stub.php @@ -90,6 +90,12 @@ class ZipArchive /** @return null|false */ public function setCommentName(string $name, string $comment) {} + /** @return null|false */ + public function setMtimeIndex(int $index, int $timestamp, int $flags = 0) {} + + /** @return null|false */ + public function setMtimeName(string $name, int $timestamp, int $flags = 0) {} + /** @return string|false */ public function getCommentIndex(int $index, int $flags = 0) {} diff --git a/ext/zip/php_zip_arginfo.h b/ext/zip/php_zip_arginfo.h index ed5ecc6a31..4839eb68b4 100644 --- a/ext/zip/php_zip_arginfo.h +++ b/ext/zip/php_zip_arginfo.h @@ -111,6 +111,18 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setCommentName, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, comment, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setMtimeIndex, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setMtimeName, 0, 0, 2) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_getCommentIndex, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) diff --git a/ext/zip/tests/oo_setmtime.phpt b/ext/zip/tests/oo_setmtime.phpt new file mode 100644 index 0000000000..aa1ceb56bb --- /dev/null +++ b/ext/zip/tests/oo_setmtime.phpt @@ -0,0 +1,76 @@ +--TEST-- +setMtime +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +if (!method_exists('ZipArchive', 'setMtimeName')) die('skip libzip too old'); +?> +--INI-- +date.timezone=UTC +--FILE-- +<?php +$dirname = dirname(__FILE__) . '/'; +include $dirname . 'utils.inc'; +$file = $dirname . '__tmp_oo_set_mtime.zip'; + +@unlink($file); + +$zip = new ZipArchive; +if (!$zip->open($file, ZIPARCHIVE::CREATE)) { + exit('failed'); +} + +$zip->addFromString('foo', 'entry #1'); +$zip->addFromString('bar', 'entry #2'); + +$t1 = mktime(0,0,0,12,25,2019); +$t2 = mktime(0,0,0,14,7,2018); + +echo "Set 1\n"; +$s = $zip->statName('foo'); +var_dump($s['mtime'] > $t1); +var_dump($zip->setMtimeName('foo', $t1)); +$s = $zip->statName('foo'); +// ONLY with 1.6.0 - var_dump($s['mtime'] == $t1); + +echo "Set 2\n"; +$s = $zip->statIndex(1); +var_dump($s['mtime'] > $t2); +var_dump($zip->setMtimeIndex(1, $t2)); +$s = $zip->statIndex(1); +// ONLY with 1.6.0 - var_dump($s['mtime'] == $t2); + +if (!$zip->status == ZIPARCHIVE::ER_OK) { + echo "failed to write zip\n"; +} +$zip->close(); + +if (!$zip->open($file)) { + @unlink($file); + exit('failed'); +} + +echo "Get 1\n"; +$s = $zip->statIndex(0); +var_dump($s['mtime'] == $t1); + +echo "Get 2\n"; +$s = $zip->statName('bar'); +var_dump($s['mtime'] == $t2); + +$zip->close(); +@unlink($file); + +?> +--EXPECTF-- +Set 1 +bool(true) +bool(true) +Set 2 +bool(true) +bool(true) +Get 1 +bool(true) +Get 2 +bool(true) |