summaryrefslogtreecommitdiff
path: root/ext/phar
diff options
context:
space:
mode:
authorGreg Beaver <cellog@php.net>2007-10-04 03:45:21 +0000
committerGreg Beaver <cellog@php.net>2007-10-04 03:45:21 +0000
commitfe8dea8a9748aee100f46850a45f292ef02ba9f3 (patch)
tree0ff9545538c6731c03ae922c2ba45076e7e87f6b /ext/phar
parent36bbdfd6f49f20453776bd7c9de5c7bc01200033 (diff)
downloadphp-git-fe8dea8a9748aee100f46850a45f292ef02ba9f3.tar.gz
MFH bugfixes of last commit
prepare release of 1.2.2
Diffstat (limited to 'ext/phar')
-rw-r--r--ext/phar/package.php18
-rw-r--r--ext/phar/package.xml74
-rw-r--r--ext/phar/phar.c57
-rwxr-xr-xext/phar/phar_internal.h5
-rwxr-xr-xext/phar/phar_object.c50
5 files changed, 144 insertions, 60 deletions
diff --git a/ext/phar/package.php b/ext/phar/package.php
index 5ae77d2f16..2e90329eaa 100644
--- a/ext/phar/package.php
+++ b/ext/phar/package.php
@@ -1,20 +1,10 @@
<?php
$notes = '
- * improve speed of uncompressed phars used readonly by 2x [Greg]
- * improve speed of phars with signatures 2x [Greg]
- * add Phar::setAlias() [Greg]
- * fix too many open file handles issue [Greg]
- * fix rename [Greg]
- * add Phar::getAlias() [Marcus]
- * Made -a optional in pack subcommand of phar.phar [Marcus]
- * Fix issue with apache module and extracted archives [Marcus]
- * Send all error messages to stderr in phar.phar [Marcus]
- * Added new subcommands add and delete to phar.phar [Marcus]
- * Made Phar::loadPhar() and Phar::mapPhar() ignore extracted archives [Marcus]
- * Fix issue with compressed entries and uncompressing entries [Marcus]
- * Verify stubs before writing [Marcus]
- * Always use longest stub end to avoid issues with length field [Marcus]
+ * fix to work with PHP 5.3
+ * fix Bug #12124: Phar object cannot be iterated over
+ * remove unused variables
+ * fix jit file open sprintf calls
';
if (!class_exists("Phar") && !extension_loaded("Phar")) {
diff --git a/ext/phar/package.xml b/ext/phar/package.xml
index 0056059743..f8a372527e 100644
--- a/ext/phar/package.xml
+++ b/ext/phar/package.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.6.2" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+<package packagerversion="1.7.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>phar</name>
<channel>pecl.php.net</channel>
<summary>allows running of complete applications out of .phar files (like Java .jar files)</summary>
@@ -29,10 +29,10 @@ avaiable then SHA-256 and SHA-512 signatures are supported as well.</description
<email>helly@php.net</email>
<active>yes</active>
</lead>
- <date>2007-08-29</date>
- <time>22:34:12</time>
+ <date>2007-10-03</date>
+ <time>22:48:03</time>
<version>
- <release>1.2.1</release>
+ <release>1.2.2</release>
<api>1.1.0</api>
</version>
<stability>
@@ -42,20 +42,10 @@ avaiable then SHA-256 and SHA-512 signatures are supported as well.</description
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- * improve speed of uncompressed phars used readonly by 2x [Greg]
- * improve speed of phars with signatures 2x [Greg]
- * add Phar::setAlias() [Greg]
- * fix too many open file handles issue [Greg]
- * fix rename [Greg]
- * add Phar::getAlias() [Marcus]
- * Made -a optional in pack subcommand of phar.phar [Marcus]
- * Fix issue with apache module and extracted archives [Marcus]
- * Send all error messages to stderr in phar.phar [Marcus]
- * Added new subcommands add and delete to phar.phar [Marcus]
- * Made Phar::loadPhar() and Phar::mapPhar() ignore extracted archives [Marcus]
- * Fix issue with compressed entries and uncompressing entries [Marcus]
- * Verify stubs before writing [Marcus]
- * Always use longest stub end to avoid issues with length field [Marcus]
+ * fix to work with PHP 5.3
+ * fix Bug #12124: Phar object cannot be iterated over
+ * remove unused variables
+ * fix jit file open sprintf calls
</notes>
<contents>
@@ -224,36 +214,52 @@ avaiable then SHA-256 and SHA-512 signatures are supported as well.</description
<changelog>
<release>
<version>
- <release>1.2.1</release>
+ <release>1.2.2</release>
<api>1.1.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
- <date>2007-08-29</date>
+ <date>2007-10-03</date>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
- * improve speed of uncompressed phars used readonly by 2x [Greg]
- * improve speed of phars with signatures 2x [Greg]
- * add Phar::setAlias() [Greg]
- * fix too many open file handles issue [Greg]
- * fix rename [Greg]
- * add Phar::getAlias() [Marcus]
- * Made -a optional in pack subcommand of phar.phar [Marcus]
- * Fix issue with apache module and extracted archives [Marcus]
- * Send all error messages to stderr in phar.phar [Marcus]
- * Added new subcommands add and delete to phar.phar [Marcus]
- * Made Phar::loadPhar() and Phar::mapPhar() ignore extracted archives [Marcus]
- * Fix issue with compressed entries and uncompressing entries [Marcus]
- * Verify stubs before writing [Marcus]
- * Always use longest stub end to avoid issues with length field [Marcus]
+ * fix to work with PHP 5.3
+ * fix Bug #12124: Phar object cannot be iterated over
+ * remove unused variables
+ * fix jit file open sprintf calls
</notes>
</release>
<release>
<version>
+ <release>1.2.1</release>
+ <api>1.1.0</api>
+ </version>
+ <stability>
+ <release>stable</release>
+ <api>stable</api>
+ </stability>
+ <date>2007-08-29</date>
+ <license uri="http://www.php.net/license">PHP License</license>
+ <notes>* improve speed of uncompressed phars used readonly by 2x [Greg]
+* improve speed of phars with signatures 2x [Greg]
+* add Phar::setAlias() [Greg]
+* fix too many open file handles issue [Greg]
+* fix rename [Greg]
+* add Phar::getAlias() [Marcus]
+* Made -a optional in pack subcommand of phar.phar [Marcus]
+* Fix issue with apache module and extracted archives [Marcus]
+* Send all error messages to stderr in phar.phar [Marcus]
+* Added new subcommands add and delete to phar.phar [Marcus]
+* Made Phar::loadPhar() and Phar::mapPhar() ignore extracted archives [Marcus]
+* Fix issue with compressed entries and uncompressing entries [Marcus]
+* Verify stubs before writing [Marcus]
+* Always use longest stub end to avoid issues with length field [Marcus]</notes>
+ </release>
+ <release>
+ <version>
<release>1.2.0</release>
<api>1.1.0</api>
</version>
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 23ac018666..7df00bb987 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -332,6 +332,15 @@ static int phar_get_archive(phar_archive_data **archive, char *fname, int fname_
*/
phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error TSRMLS_DC) /* {{{ */
{
+ return phar_get_entry_info_dir(phar, path, path_len, 0, error TSRMLS_CC);
+}
+/* }}} */
+
+/**
+ * retrieve information on a file or directory contained within a phar, or null if none found
+ */
+phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error TSRMLS_DC) /* {{{ */
+{
const char *pcr_error;
phar_entry_info *entry;
@@ -356,6 +365,41 @@ phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int pa
}
return entry;
}
+ if (dir) {
+ /* try to find a directory */
+ HashTable *manifest;
+ char *key;
+ uint keylen;
+ ulong unused;
+
+ manifest = &phar->manifest;
+ zend_hash_internal_pointer_reset(manifest);
+ while (FAILURE != zend_hash_has_more_elements(manifest)) {
+ if (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key_ex(manifest, &key, &keylen, &unused, 0, NULL)) {
+ break;
+ }
+ if (0 != memcmp(key, path, path_len)) {
+ /* entry in directory not found */
+ if (SUCCESS != zend_hash_move_forward(manifest)) {
+ break;
+ }
+ continue;
+ } else {
+ if (key[path_len] != '/') {
+ if (SUCCESS != zend_hash_move_forward(manifest)) {
+ break;
+ }
+ continue;
+ }
+ /* found a file in this path */
+ entry = (phar_entry_info *) ecalloc(1, sizeof(phar_entry_info));
+ entry->is_dir = 1;
+ entry->filename = (char *) estrndup(path, path_len + 1);
+ entry->filename_len = path_len;
+ return entry;
+ }
+ }
+ }
return NULL;
}
/* }}} */
@@ -1707,7 +1751,7 @@ static phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info
offset = phar->internal_file_start + entry->offset_within_phar;
if (-1 == php_stream_seek(fp, offset, SEEK_SET)) {
spprintf(error, 0, "phar error: internal corruption of phar \"%s\" (cannot seek to start of file \"%s\" at offset \"%d\")",
- phar->fname, entry, offset);
+ phar->fname, entry->filename, offset);
return NULL;
}
@@ -1724,7 +1768,7 @@ static phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info
filter = NULL;
}
if (!filter) {
- spprintf(error, 0, "phar error: unable to read phar \"%s\" (cannot create %s filter while decompressing file \"%s\")", phar->fname, phar_decompress_filter(entry, 1), entry);
+ spprintf(error, 0, "phar error: unable to read phar \"%s\" (cannot create %s filter while decompressing file \"%s\")", phar->fname, phar_decompress_filter(entry, 1), entry->filename);
return NULL;
}
/* now we can safely use proper decompression */
@@ -1791,16 +1835,11 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, char *pat
{
phar_entry_data *idata;
char *internal_file;
- char *buffer;
char *error;
- char *filter_name;
char *plain_map;
- char tmpbuf[8];
HashTable *pharcontext;
php_url *resource = NULL;
php_stream *fp, *fpf;
- php_stream_filter *filter/*, *consumed */;
- php_uint32 offset, read, total, toread;
zval **pzoption, *metadata;
uint host_len;
@@ -2220,7 +2259,7 @@ int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **err
long offset;
size_t wrote;
php_uint32 manifest_len, mytime, loc, new_manifest_count;
- php_uint32 newcrc32, save;
+ php_uint32 newcrc32;
php_stream *file, *oldfile, *newfile, *stubfile;
php_stream_filter *filter;
php_serialize_data_t metadata_hash;
@@ -3215,7 +3254,7 @@ PHAR_ADD_ENTRY:
}
/* }}}*/
-#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 50300 || PHP_VERSION_ID >= 60000)
+#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID < 50400 || PHP_VERSION_ID >= 60000)
static int _php_stream_unlink(char *url, int options, php_stream_context *context TSRMLS_DC)
{
diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h
index acfc15b60e..8fdfefe24f 100755
--- a/ext/phar/phar_internal.h
+++ b/ext/phar/phar_internal.h
@@ -62,7 +62,7 @@
#define E_RECOVERABLE_ERROR E_ERROR
#endif
-#define PHAR_EXT_VERSION_STR "1.2.1"
+#define PHAR_EXT_VERSION_STR "1.2.2"
#define PHAR_API_VERSION_STR "1.1.0"
/* x.y.z maps to 0xyz0 */
#define PHAR_API_VERSION 0x1100
@@ -159,6 +159,8 @@ typedef struct _phar_entry_info {
int is_crc_checked:1;
int is_modified:1;
int is_deleted:1;
+ /* used when iterating */
+ int is_dir:1;
phar_archive_data *phar;
smart_str metadata_str;
} phar_entry_info;
@@ -271,6 +273,7 @@ int phar_archive_delref(phar_archive_data *phar TSRMLS_DC);
int phar_entry_delref(phar_entry_data *idata TSRMLS_DC);
phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len, char **error TSRMLS_DC);
+phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, int path_len, char dir, char **error TSRMLS_DC);
phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char *path, int path_len, char *mode, char **error TSRMLS_DC);
int phar_flush(phar_archive_data *archive, char *user_stub, long len, char **error TSRMLS_DC);
int phar_detect_phar_fname_ext(const char *filename, int check_length, char **ext_str, int *ext_len);
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 926aff14bc..57c7485299 100755
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -1037,10 +1037,10 @@ PHP_METHOD(PharFileInfo, __construct)
return;
}
- if ((entry_info = phar_get_entry_info(phar_data, entry, entry_len, &error TSRMLS_CC)) == NULL) {
- efree(arch);
+ if ((entry_info = phar_get_entry_info_dir(phar_data, entry, entry_len, 1, &error TSRMLS_CC)) == NULL) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
"Cannot access phar file entry '%s' in archive '%s'%s%s", entry, arch, error?", ":"", error?error:"");
+ efree(arch);
efree(entry);
return;
}
@@ -1065,6 +1065,23 @@ PHP_METHOD(PharFileInfo, __construct)
"Cannot call method on an uninitialized PharFileInfo object"); \
return; \
}
+/* {{{ proto void PharFileInfo::__destruct()
+ * clean up directory-based entry objects
+ */
+PHP_METHOD(PharFileInfo, __destruct)
+{
+ PHAR_ENTRY_OBJECT();
+
+ if (entry_obj->ent.entry->is_dir) {
+ if (entry_obj->ent.entry->filename) {
+ efree(entry_obj->ent.entry->filename);
+ entry_obj->ent.entry->filename = NULL;
+ }
+ efree(entry_obj->ent.entry);
+ entry_obj->ent.entry = NULL;
+ }
+}
+/* }}} */
/* {{{ proto int PharFileInfo::getCompressedSize()
* Returns the compressed size
@@ -1117,6 +1134,10 @@ PHP_METHOD(PharFileInfo, getCRC32)
{
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, does not have a CRC"); \
+ }
if (entry_obj->ent.entry->is_crc_checked) {
RETURN_LONG(entry_obj->ent.entry->crc32);
} else {
@@ -1157,6 +1178,10 @@ PHP_METHOD(PharFileInfo, chmod)
long perms;
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, cannot chmod"); \
+ }
if (PHAR_G(readonly)) {
zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Cannot modify permissions for file \"%s\" write operations are prohibited", entry_obj->ent.entry->filename, entry_obj->ent.entry->phar->fname);
}
@@ -1222,6 +1247,10 @@ PHP_METHOD(PharFileInfo, setMetadata)
zval *metadata;
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, cannot set metadata"); \
+ }
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &metadata) == FAILURE) {
return;
}
@@ -1250,6 +1279,10 @@ PHP_METHOD(PharFileInfo, delMetadata)
char *error;
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, cannot delete metadata"); \
+ }
if (entry_obj->ent.entry->metadata) {
zval_ptr_dtor(&entry_obj->ent.entry->metadata);
entry_obj->ent.entry->metadata = NULL;
@@ -1277,6 +1310,10 @@ PHP_METHOD(PharFileInfo, setCompressedGZ)
char *error;
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, cannot set compression"); \
+ }
if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ) {
RETURN_TRUE;
return;
@@ -1317,6 +1354,10 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2)
char *error;
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, cannot set compression"); \
+ }
if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
RETURN_TRUE;
return;
@@ -1357,6 +1398,10 @@ PHP_METHOD(PharFileInfo, setUncompressed)
int fname_len;
PHAR_ENTRY_OBJECT();
+ if (entry_obj->ent.entry->is_dir) {
+ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
+ "Phar entry is a directory, cannot set compression"); \
+ }
if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSION_MASK) == 0) {
RETURN_TRUE;
return;
@@ -1497,6 +1542,7 @@ ZEND_END_ARG_INFO();
zend_function_entry php_entry_methods[] = {
PHP_ME(PharFileInfo, __construct, arginfo_entry___construct, 0)
+ PHP_ME(PharFileInfo, __destruct, NULL, 0)
PHP_ME(PharFileInfo, getCompressedSize, NULL, 0)
PHP_ME(PharFileInfo, isCompressed, NULL, 0)
PHP_ME(PharFileInfo, isCompressedGZ, NULL, 0)