From: Greg Beaver Date: Mon, 18 Feb 2008 04:45:42 +0000 (+0000) Subject: add initial support for hashing mounted directories. Actual matching of mounted... X-Git-Tag: RELEASE_2_0_0a1~443 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba9fcf62fcf90f0568227a48c96ab828128e61ed;p=php add initial support for hashing mounted directories. Actual matching of mounted directories is not yet supported. --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 575bfb278c..f185f7d445 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -186,6 +186,10 @@ static void phar_destroy_phar_data(phar_archive_data *phar TSRMLS_DC) /* {{{ */ zend_hash_destroy(&phar->manifest); phar->manifest.arBuckets = NULL; } + if (phar->mounted_dirs.arBuckets) { + zend_hash_destroy(&phar->mounted_dirs); + phar->mounted_dirs.arBuckets = NULL; + } if (phar->metadata) { zval_ptr_dtor(&phar->metadata); phar->metadata = 0; @@ -838,6 +842,8 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int /* set up our manifest */ zend_hash_init(&mydata->manifest, sizeof(phar_entry_info), zend_get_hash_value, destroy_phar_manifest_entry, 0); + zend_hash_init(&mydata->mounted_dirs, sizeof(char *), + zend_get_hash_value, NULL, 0); offset = halt_offset + manifest_len + 4; memset(&entry, 0, sizeof(phar_entry_info)); entry.phar = mydata; diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index f8be40ca70..7d18be8a0b 100755 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -261,6 +261,8 @@ struct _phar_archive_data { size_t internal_file_start; size_t halt_offset; HashTable manifest; + /* hash of mounted directory paths */ + HashTable mounted_dirs; php_uint32 flags; php_uint32 min_timestamp; php_uint32 max_timestamp; diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 6554796052..dd754137d2 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -170,6 +170,8 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i myphar = (phar_archive_data *) ecalloc(1, sizeof(phar_archive_data)); zend_hash_init(&myphar->manifest, sizeof(phar_entry_info), zend_get_hash_value, destroy_phar_manifest_entry, 0); + zend_hash_init(&myphar->mounted_dirs, sizeof(char *), + zend_get_hash_value, NULL, 0); myphar->is_tar = 1; /* remember whether this entire phar was compressed with gz/bzip2 */ myphar->flags = compression; diff --git a/ext/phar/util.c b/ext/phar/util.c index 519dfdfc50..c690e05e00 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -108,7 +108,17 @@ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, efree(entry.filename); return FAILURE; } - entry.is_dir = ssb.sb.st_mode & S_IFDIR ? 1 : 0; + if (ssb.sb.st_mode & S_IFDIR) { + entry.is_dir = 1; + if (SUCCESS != zend_hash_add(&phar->mounted_dirs, path, path_len, (void *)&path, sizeof(char *), NULL)) { + /* directory already mounted */ + efree(entry.link); + efree(entry.filename); + return FAILURE; + } + } else { + entry.is_dir = 0; + } 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)) { diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 6d5a8b522f..8c64083043 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -208,6 +208,8 @@ foundit: /* read in central directory */ zend_hash_init(&mydata->manifest, sizeof(phar_entry_info), zend_get_hash_value, destroy_phar_manifest_entry, 0); + zend_hash_init(&mydata->mounted_dirs, sizeof(char *), + zend_get_hash_value, NULL, 0); entry.phar = mydata; entry.is_zip = 1; entry.fp_type = PHAR_FP;