]> granicus.if.org Git - php/commitdiff
add externally parsed files to temporary manifest (this will be made
authorGreg Beaver <cellog@php.net>
Mon, 18 Feb 2008 03:37:51 +0000 (03:37 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 18 Feb 2008 03:37:51 +0000 (03:37 +0000)
optional and must be explicitly enabled per-phar)

ext/phar/phar.c
ext/phar/tests/tempmanifest1.phpt [new file with mode: 0644]
ext/phar/util.c

index 3904043fbc0aaad213203934a840c81734d415c5..d86856f9a992356ffb51c02dd53cc1af6f1a4feb 100644 (file)
@@ -2567,12 +2567,19 @@ int phar_zend_open(const char *filename, zend_file_handle *handle TSRMLS_DC) /*
                                if (SUCCESS == (zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **) &pphar))) {
                                        if (!(entry = phar_find_in_include_path(entry, old, *pphar TSRMLS_CC))) {
                                                /* this file is not in the phar, use the original path */
+                                               if (SUCCESS == phar_orig_zend_open(filename, handle TSRMLS_CC)) {
+                                                       if (filename[0] != '.' && SUCCESS == phar_mount_entry(*pphar, handle->opened_path ? handle->opened_path : filename, strlen(handle->opened_path ? handle->opened_path : filename), filename, strlen(filename), 0)) {
+                                                               entry = (char *) filename;
+                                                               goto dopharthing;
+                                                       }
+                                               }
                                                efree(old);
                                                efree(arch);
                                                goto skip_phar;
                                        }
                                }
                        }
+dopharthing:
                        efree(old);
                        /* auto-convert to phar:// */
                        spprintf(&name, 4096, "phar://%s/%s", arch, entry);
diff --git a/ext/phar/tests/tempmanifest1.phpt b/ext/phar/tests/tempmanifest1.phpt
new file mode 100644 (file)
index 0000000..bff1026
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Phar: temporary manifest entry test
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$fname = dirname(__FILE__) . '/tempmanifest1.phar.php';
+$a = new Phar($fname);
+$a['index.php'] = '<?php
+set_include_path("' . addslashes(dirname(__FILE__)) . '");
+include "extfile.php";
+?>';
+$a->setStub('<?php
+include "phar://" . __FILE__ . "/index.php";
+__HALT_COMPILER();');
+unset($a);
+file_put_contents(dirname(__FILE__) . '/extfile.php', '<?php
+var_dump(__FILE__);
+?>');
+include dirname(__FILE__) . '/extfile.php';
+include $fname;
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tempmanifest1.phar.php');
+@unlink(dirname(__FILE__) . '/extfile.php');
+?>
+--EXPECTF--
+string(%d) "%sextfile.php"
+string(%d) "phar://%sextfile.php"
+===DONE===
\ No newline at end of file
index d01c8cd3706e738bd6bce565d89613c3ace296d3..809835832ef3df3cf202858e9cdb06ed7775e2cb 100644 (file)
@@ -78,6 +78,7 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi
 int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len, int is_dir TSRMLS_DC)
 {
        phar_entry_info entry = {0};
+       php_stream_statbuf ssb;
 
 #if PHP_MAJOR_VERSION < 6
        if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_ALLOW_ONLY_FILE))) {
@@ -98,7 +99,20 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len,
        entry.is_crc_checked = 1;
        entry.fp_type = PHAR_TMP;
        entry.is_dir = is_dir;
-       return zend_hash_add(&phar->manifest, path, path_len, (void*)&entry, sizeof(phar_entry_info), NULL);
+
+       if (SUCCESS != php_stream_stat_path(entry.link, &ssb)) {
+               efree(entry.link);
+               efree(entry.filename);
+               return FAILURE;
+       }
+       entry.uncompressed_filesize = entry.compressed_filesize = ssb.sb.st_size;
+       entry.flags = ssb.sb.st_mode;
+       if (SUCCESS == zend_hash_add(&phar->manifest, path, path_len, (void*)&entry, sizeof(phar_entry_info), NULL)) {
+               return SUCCESS;
+       }
+       efree(entry.link);
+       efree(entry.filename);
+       return FAILURE;
 }
 
 char *phar_find_in_include_path(char *file, char *entry, phar_archive_data *phar TSRMLS_DC) /* {{{ */
@@ -416,6 +430,12 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC)
        char *filtername;
        off_t loc;
 
+       if (entry->fp_type == PHAR_TMP) {
+               if (!entry->fp) {
+                       entry->fp = php_stream_open_wrapper(entry->link, "rb", STREAM_MUST_SEEK|0, NULL);
+               }
+               return SUCCESS;
+       }
        if (entry->fp_type != PHAR_FP) {
                /* either newly created or already modified */
                return SUCCESS;