diff options
| -rw-r--r-- | ext/phar/TODO | 2 | ||||
| -rw-r--r-- | ext/phar/package.php | 1 | ||||
| -rwxr-xr-x | ext/phar/phar_object.c | 36 | ||||
| -rw-r--r-- | ext/phar/tests/phar_copy.phpt | 28 |
4 files changed, 39 insertions, 28 deletions
diff --git a/ext/phar/TODO b/ext/phar/TODO index 18d9e4d0f0..88f0f7ca42 100644 --- a/ext/phar/TODO +++ b/ext/phar/TODO @@ -68,7 +68,7 @@ Version 1.3.0 * implement PPG signing * ability to match files containing a metadata key opendir('phar://a.phar/?mime-type=image/jpeg') or foreach ($p->match('mime-type', 'image/jpeg') as $file) - * Phar::copy($from, $to); + X Phar::copy($from, $to); [Greg] X Phar::delete($what) [Greg] X Phar::buildFromIterator(Iterator $it[, string $base_directory]) [Greg] * Layout: Option to compress all content rather than single files. diff --git a/ext/phar/package.php b/ext/phar/package.php index 2482c145e6..078e1811fb 100644 --- a/ext/phar/package.php +++ b/ext/phar/package.php @@ -1,6 +1,7 @@ <?php $notes = ' + * implement Phar::copy(string $from, string $to) [Greg] * implement Phar::buildFromIterator(Iterator $it[, string $base_directory]) [Greg] * add mapping of include/require from within a phar to location within phar [Greg] solves the include_path issue without code munging diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 87cb1a3aaa..7e97fdc2b3 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1106,35 +1106,35 @@ PHP_METHOD(Phar, copy) RETURN_FALSE; } - if (!zend_hash_exists(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len)) { - if (SUCCESS != zend_hash_find(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len, (void**)&oldentry) || oldentry->is_deleted) { - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->arc.archive->fname); - RETURN_FALSE; - } + if (!zend_hash_exists(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len) || SUCCESS != zend_hash_find(&phar_obj->arc.archive->manifest, oldfile, (uint) oldfile_len, (void**)&oldentry) || oldentry->is_deleted) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->arc.archive->fname); + RETURN_FALSE; } - if (oldentry->fp && oldentry->fp != phar_obj->arc.archive->fp) { + fp = oldentry->fp; + if (fp && fp != phar_obj->arc.archive->fp) { /* new file */ - fp = oldentry->fp; + newentry.fp = php_stream_temp_new(); + fp = newentry.fp; php_stream_seek(fp, 0, SEEK_SET); - } else { - fp = phar_obj->arc.archive->fp; - php_stream_seek(fp, phar_obj->arc.archive->internal_file_start + oldentry->offset_within_phar, SEEK_SET); - } - newentry.fp = php_stream_temp_new(); - if (oldentry->compressed_filesize != php_stream_copy_to_stream(fp, newentry.fp, oldentry->compressed_filesize)) { - php_stream_close(newentry.fp); - zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, - "file \"%s\" could not be copied to file \"%s\" in %s, copy failed", oldfile, newfile, phar_obj->arc.archive->fname); + if (oldentry->compressed_filesize != php_stream_copy_to_stream(oldentry->fp, fp, oldentry->compressed_filesize)) { + php_stream_close(fp); + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "file \"%s\" could not be copied to file \"%s\" in %s, copy failed", oldfile, newfile, phar_obj->arc.archive->fname); + } } - fp = newentry.fp; memcpy((void *) &newentry, oldentry, sizeof(phar_entry_info)); if (newentry.metadata) { SEPARATE_ZVAL(&(newentry.metadata)); + newentry.metadata_str.c = NULL; + newentry.metadata_str.len = 0; } newentry.fp = fp; + newentry.filename = estrndup(newfile, newfile_len); + newentry.filename_len = newfile_len; + phar_obj->arc.archive->is_modified = 1; zend_hash_add(&phar_obj->arc.archive->manifest, newfile, newfile_len, (void*)&newentry, sizeof(phar_entry_info), NULL); phar_flush(phar_obj->arc.archive, 0, 0, &error TSRMLS_CC); diff --git a/ext/phar/tests/phar_copy.phpt b/ext/phar/tests/phar_copy.phpt index 5ad0ccef21..8fe3471179 100644 --- a/ext/phar/tests/phar_copy.phpt +++ b/ext/phar/tests/phar_copy.phpt @@ -11,34 +11,44 @@ phar.require_hash=1 <?php $fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php'; +$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '2.phar.php'; + $pname = 'phar://'.$fname; $iname = '/file.txt'; $ename = '/error/'; $p = new Phar($fname); -$p[$iname] = "foobar\n"; try { $p['a'] = 'hi'; + $p->startBuffering(); $p->copy('a', 'b'); - echo $p['b']; + echo file_get_contents($p['b']->getPathName()); $p['a']->setCompressedGZ(); - $p->copy('a', 'c'); - echo $p['c']; + $p['b']->setMetadata('a'); + $p->copy('b', 'c'); + $p->stopBuffering(); + echo file_get_contents($p['c']->getPathName()); + copy($fname, $fname2); $p->copy('a', $ename); } catch(Exception $e) { echo $e->getMessage() . "\n"; } - -include($pname . $iname); +ini_set('phar.readonly',1); +$p2 = new Phar($fname2); +echo "\n"; +echo 'a: ' , file_get_contents($p2['a']->getPathName()); +echo 'b: ' ,file_get_contents($p2['b']->getPathName()); +echo 'c: ' ,file_get_contents($p2['c']->getPathName()), $p2['c']->getMetaData(); ?> ===DONE=== --CLEAN-- <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?> +<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '2.phar.php'); ?> --EXPECTF-- -hihi -file "/error/" contains invalid characters /, cannot be copied from "a" in phar %s -===DONE=== +hihifile "/error/" contains invalid characters empty directory, cannot be copied from "a" in phar %s + +a: hib: hic: hia===DONE===
\ No newline at end of file |
