summaryrefslogtreecommitdiff
path: root/ext/phar
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2008-09-13 20:57:15 +0000
committerGreg Beaver <cellog@php.net>2008-09-13 20:57:15 +0000
commita32388a9dc33db8baa3fe44dee6190e611634c70 (patch)
tree02737168c7587b31d889669c78f0333e2664dac1 /ext/phar
parent09e9f4cda1a3e8b2f9e1345d050a22e3552a3a50 (diff)
downloadphp-git-a32388a9dc33db8baa3fe44dee6190e611634c70.tar.gz
MFB: fix Bug #46060: addEmptyDir() breaks
Diffstat (limited to 'ext/phar')
-rw-r--r--ext/phar/tests/bug46060.phpt30
-rw-r--r--ext/phar/util.c10
2 files changed, 35 insertions, 5 deletions
diff --git a/ext/phar/tests/bug46060.phpt b/ext/phar/tests/bug46060.phpt
new file mode 100644
index 0000000000..7edae4d43c
--- /dev/null
+++ b/ext/phar/tests/bug46060.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Phar: Bug #46060: addEmptyDir() breaks
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (getenv('SKIP_SLOW_TESTS')) die('skip'); ?>
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.tar';
+$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.2.tar';
+
+$phar = new PharData($fname);
+$phar->addEmptyDir('blah/');
+$phar->addFromString('test/', '');
+
+copy($fname, $fname2);
+$phar = new PharData($fname2);
+
+var_dump($phar['blah']->isDir(), $phar['test']->isDir());
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.tar');
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.2.tar');
+__HALT_COMPILER();
+?>
+--EXPECT--
+bool(true)
+bool(false)
+===DONE===
diff --git a/ext/phar/util.c b/ext/phar/util.c
index 0723cd2508..814a3cbd17 100644
--- a/ext/phar/util.c
+++ b/ext/phar/util.c
@@ -785,13 +785,13 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
if (allow_dir == 2) {
etemp.is_dir = 1;
etemp.flags = etemp.old_flags = PHAR_ENT_PERM_DEF_DIR;
- if (is_dir) {
- etemp.filename_len--; /* strip trailing / */
- path_len--;
- }
} else {
etemp.flags = etemp.old_flags = PHAR_ENT_PERM_DEF_FILE;
}
+ if (is_dir) {
+ etemp.filename_len--; /* strip trailing / */
+ path_len--;
+ }
phar_add_virtual_dirs(phar, path, path_len TSRMLS_CC);
etemp.is_modified = 1;
@@ -803,7 +803,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char
if (phar->is_tar) {
etemp.is_tar = phar->is_tar;
- etemp.tar_type = TAR_FILE;
+ etemp.tar_type = etemp.is_dir ? TAR_DIR : TAR_FILE;
}
if (FAILURE == zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), (void **) &entry)) {