]> granicus.if.org Git - php/commitdiff
- bump zip extension version to 1.16.0 - add ZipArchive::setMtimeName and ZipArchive...
authorRemi Collet <remi@remirepo.net>
Tue, 28 Jan 2020 09:52:09 +0000 (10:52 +0100)
committerRemi Collet <remi@php.net>
Tue, 28 Jan 2020 09:53:49 +0000 (10:53 +0100)
NEWS
ext/zip/config.m4
ext/zip/php_zip.c
ext/zip/php_zip.h
ext/zip/php_zip.stub.php
ext/zip/php_zip_arginfo.h
ext/zip/tests/oo_setmtime.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 8290ac3d81ac941106e1d074b6fff0a5c89de5b0..effc968cf40a672eb55cd5641790a85de3ce8800 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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! >>>
index 0b151b7f2ae32d18482ec2bb534e14af69d5f956..669adb6b9aeda3ba0da5442dc3e67e996640132a 100644 (file)
@@ -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])
index d39ad316ae9b6c9bcf91c7a5b9367901e3ee2a60..1218d707f0ab5ecd2017fde6a42ebdfa21cfbda9 100644 (file)
@@ -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)
index f900632e56288bc78bb891db5160d3f060c60b3d..d1f46ea4ea24c9f924a1ff542da9412094bcda49 100644 (file)
@@ -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)
 
index e312bfd0312d0e8add8bbcf722e52b36b866c819..c88d2742eeee8d4d6dac51d867f4b22ce09d9ca5 100644 (file)
@@ -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) {}
 
index ed5ecc6a31263b1665501926d566f4a2d1625566..4839eb68b4afed4682de3787b7017840b3254152 100644 (file)
@@ -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 (file)
index 0000000..aa1ceb5
--- /dev/null
@@ -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)