summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2007-01-05 01:50:26 +0000
committerGreg Beaver <cellog@php.net>2007-01-05 01:50:26 +0000
commit00f516cc99e107bc315172251c66ba562210f507 (patch)
tree30113585832ca54b0f2ba7c539d01cccaa681414 /ext
parentfe0f4b6a00b586e2ddc0463dcefa3918c198908d (diff)
downloadphp-git-00f516cc99e107bc315172251c66ba562210f507.tar.gz
fix creation of new files within an existing phar, add test
Diffstat (limited to 'ext')
-rw-r--r--ext/phar/phar.c14
-rw-r--r--ext/phar/tests/open_for_write_existing.phpt1
-rw-r--r--ext/phar/tests/open_for_write_newfile.phpt41
3 files changed, 50 insertions, 6 deletions
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index bbbf069090..912a5431ce 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -374,10 +374,11 @@ static phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len
ret->internal_file->crc32 = 0;
return ret;
}
- /* create an entry, this is a new file */
- if ((entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC)) != NULL) {
- ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
- entry = (phar_entry_info *) emalloc(sizeof(phar_entry_info));
+ /* create a new phar data holder */
+ ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
+ if ((entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC)) == NULL) {
+ /* create an entry, this is a new file */
+ etemp.flags = 0;
etemp.filename_len = path_len;
etemp.filename = estrndup(path, path_len);
etemp.uncompressed_filesize = 0;
@@ -388,8 +389,9 @@ static phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len
etemp.crc_checked = TRUE;
etemp.fp = NULL;
etemp.temp_file = 0;
- memcpy((void *) entry, (void *) &etemp, sizeof(phar_entry_info));
- zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)entry, sizeof(phar_entry_info), NULL);
+ zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), NULL);
+ /* retrieve the phar manifest copy */
+ entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC);
}
ret->phar = phar;
ret->internal_file = entry;
diff --git a/ext/phar/tests/open_for_write_existing.phpt b/ext/phar/tests/open_for_write_existing.phpt
index 769f6e4640..81a7217bff 100644
--- a/ext/phar/tests/open_for_write_existing.phpt
+++ b/ext/phar/tests/open_for_write_existing.phpt
@@ -30,6 +30,7 @@ fwrite($fp, 'extra');
fclose($fp);
include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php';
?>
+
===DONE===
--CLEAN--
<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
diff --git a/ext/phar/tests/open_for_write_newfile.phpt b/ext/phar/tests/open_for_write_newfile.phpt
new file mode 100644
index 0000000000..ed017d733c
--- /dev/null
+++ b/ext/phar/tests/open_for_write_newfile.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Phar: fopen a .phar for writing (new file)
+--SKIPIF--
+<?php if (!extension_loaded("phar")) print "skip"; ?>
+--FILE--
+<?php
+$file = "<?php __HALT_COMPILER(); ?>";
+
+$files = array();
+$files['a.php'] = '<?php echo "This is a\n"; ?>';
+$files['b.php'] = '<?php echo "This is b\n"; ?>';
+$files['b/c.php'] = '<?php echo "This is b/c\n"; ?>';
+$manifest = '';
+foreach($files as $name => $cont) {
+ $len = strlen($cont);
+ $manifest .= pack('V', strlen($name)) . $name . pack('VVVVC', $len, time(), $len, crc32($cont), 0x00);
+}
+$alias = '';
+$manifest = pack('VnV', count($files), 0x0800, strlen($alias)) . $alias . $manifest;
+$file .= pack('V', strlen($manifest)) . $manifest;
+foreach($files as $cont)
+{
+ $file .= $cont;
+}
+
+file_put_contents(dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php', $file);
+
+$fp = fopen('phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php', 'wb');
+fwrite($fp, 'extra');
+fclose($fp);
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/c.php';
+include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php/b/new.php';
+?>
+
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+This is b/c
+extra
+===DONE===