zval *this = getThis();
char *dirname;
int dirname_len;
+ int idx;
+ struct zip_stat sb;
+ char *s;
if (!this) {
RETURN_FALSE;
&dirname, &dirname_len, UG(ascii_conv)) == FAILURE) {
return;
}
+
if (dirname_len<1) {
RETURN_FALSE;
}
- if (zip_add_dir(intern, (const char *)dirname) < 0) {
- RETURN_FALSE;
+ if (dirname[dirname_len-1] != '/') {
+ s=(char *)emalloc(dirname_len+2);
+ strcpy(s, dirname);
+ s[dirname_len] = '/';
+ s[dirname_len+1] = '\0';
+ } else {
+ s = dirname;
+ }
+
+ idx = zip_stat(intern, s, 0, &sb);
+ if (idx >= 0) {
+ RETVAL_FALSE;
+ } else {
+ /* reset the error */
+ if (intern->error.str) {
+ _zip_error_fini(&intern->error);
+ }
+ _zip_error_init(&intern->error);
+
+ if (zip_add_dir(intern, (const char *)s) == -1) {
+ RETVAL_FALSE;
+ }
+ RETVAL_TRUE;
+ }
+
+ if (s != dirname) {
+ efree(s);
}
- RETURN_TRUE;
}
/* }}} */
--- /dev/null
+--TEST--
+Bug #11216 (::addEmptyDir() crashes when the directory already exists)
+--SKIPIF--
+<?php
+/* $Id$ */
+if(!extension_loaded('zip')) die('skip');
+ ?>
+--FILE--
+<?php
+$archive = new ZipArchive();
+$archive->open('__test.zip', ZIPARCHIVE::CREATE);
+var_dump($archive->addEmptyDir('test'));
+print_r($archive);
+var_dump($archive->addEmptyDir('test'));
+$archive->close();
+unlink('__test.zip');
+?>
+--EXPECT--
+bool(true)
+ZipArchive Object
+(
+ [status] => 0
+ [statusSys] => 0
+ [numFiles] => 1
+ [filename] =>
+ [comment] =>
+)
+bool(false)