pajoye          Mon Jan 29 16:01:55 2007 UTC

  Modified files:              
    /php-src/ext/zip    php_zip.c 
    /php-src/ext/zip/tests      bug40228.phpt bug40228.zip 
  Log:
  - MFB: #40228, ZipArchive::extractTo does create empty directories
   recursively
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/php_zip.c?r1=1.37&r2=1.38&diff_format=u
Index: php-src/ext/zip/php_zip.c
diff -u php-src/ext/zip/php_zip.c:1.37 php-src/ext/zip/php_zip.c:1.38
--- php-src/ext/zip/php_zip.c:1.37      Sat Jan  6 20:30:23 2007
+++ php-src/ext/zip/php_zip.c   Mon Jan 29 16:01:55 2007
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_zip.c,v 1.37 2007/01/06 20:30:23 nlopess Exp $ */
+/* $Id: php_zip.c,v 1.38 2007/01/29 16:01:55 pajoye Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -101,23 +101,28 @@
 
        char *file_basename;
        size_t file_basename_len;
+       int is_dir_only = 0;
 
        if (file_len >= MAXPATHLEN || zip_stat(za, file, 0, &sb)) {
                return 0;
        }
 
-       memcpy(file_dirname, file, file_len);
-
-       dir_len = php_dirname(file_dirname, file_len);
-
-       if (dir_len > 0) {
-               len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, 
file_dirname);
+       if (file_len > 1 && file[file_len - 1] == '/') {
+               len = spprintf(&file_dirname_fullpath, 0, "%s/%s", dest, file);
+               is_dir_only = 1;
        } else {
-               len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
-       }
+               memcpy(file_dirname, file, file_len);
 
-       php_basename(file, file_len, NULL, 0, &file_basename, 
&file_basename_len TSRMLS_CC);
+               dir_len = php_dirname(file_dirname, file_len);
+
+               if (dir_len > 0) {
+                       len = spprintf(&file_dirname_fullpath, 0, "%s/%s", 
dest, file_dirname);
+               } else {
+                       len = spprintf(&file_dirname_fullpath, 0, "%s", dest);
+               }
 
+               php_basename(file, file_len, NULL, 0, &file_basename, (unsigned 
int *)&file_basename_len TSRMLS_CC);
+       }
        /* let see if the path already exists */
        if (php_stream_stat_path(file_dirname_fullpath, &ssb) < 0) {
                ret = php_stream_mkdir(file_dirname_fullpath, 0777,  
PHP_STREAM_MKDIR_RECURSIVE, NULL);
@@ -131,7 +136,9 @@
        /* it is a standalone directory, job done */
        if (file[file_len - 1] == '/') {
                efree(file_dirname_fullpath);
-               efree(file_basename);
+               if (!is_dir_only) {
+                       efree(file_basename);
+               }
                return 1;
        }
 
@@ -2076,7 +2083,7 @@
        php_info_print_table_start();
 
        php_info_print_table_row(2, "Zip", "enabled");
-       php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.37 
2007/01/06 20:30:23 nlopess Exp $");
+       php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.38 
2007/01/29 16:01:55 pajoye Exp $");
        php_info_print_table_row(2, "Zip version", "2.0.0");
        php_info_print_table_row(2, "Libzip version", "0.7.1");
 
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/bug40228.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/zip/tests/bug40228.phpt
diff -u /dev/null php-src/ext/zip/tests/bug40228.phpt:1.2
--- /dev/null   Mon Jan 29 16:01:55 2007
+++ php-src/ext/zip/tests/bug40228.phpt Mon Jan 29 16:01:55 2007
@@ -0,0 +1,23 @@
+--TEST--
+Bug #40228 (extractTo does not create recursive empty path)
+--SKIPIF--
+<?php if (!extension_loaded("zip")) print "skip"; ?>
+--FILE--
+<?php
+$dest = dirname(__FILE__);
+$arc_name = $dest . "/bug40228.zip";
+$zip = new ZipArchive;
+$zip->open($arc_name, ZIPARCHIVE::CREATE);;
+$zip->extractTo($dest);
+if (is_dir($dest . '/test/empty')) {
+       echo "Ok\n";
+       rmdir($dest . '/test/empty');
+       rmdir($dest . '/test');
+} else {
+       echo "Failed.\n";
+}
+echo "Done\n";
+?>
+--EXPECT--
+Ok
+Done
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/bug40228.zip?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/zip/tests/bug40228.zip

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to