diff options
| author | Greg Beaver <cellog@php.net> | 2008-03-23 22:42:45 +0000 |
|---|---|---|
| committer | Greg Beaver <cellog@php.net> | 2008-03-23 22:42:45 +0000 |
| commit | 95eeee9156a88eec0ddbb17cb31a74b8a36069c3 (patch) | |
| tree | cf1df0f0261384a201d77ae37cbf9a9125538d34 /ext/phar/util.c | |
| parent | cac70206f27c1c8937236dd9750e5b0b4655909a (diff) | |
| download | php-git-95eeee9156a88eec0ddbb17cb31a74b8a36069c3.tar.gz | |
not all tests have been converted over to the new API, but it works
conversion is now split into 3 separate methods
1\) convertToZip\(\) convertToTar\(\) and convertToPhar\(\) exclusively change file format
2\) compress\(\) sets compression, accepting Phar::GZ, Phar::BZ2, or Phar::NONE
3\) convertToExecutable\(\) allows stub creation in tar/zip, convertToData\(\) prevents it
all methods return either Phar or PharData objects, allowing fluent interface.
only 1 test has been converted to the new format, but the API works
Diffstat (limited to 'ext/phar/util.c')
| -rw-r--r-- | ext/phar/util.c | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/ext/phar/util.c b/ext/phar/util.c index aa3801ae0f..d3f198c9be 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -75,110 +75,6 @@ int phar_seek_efp(phar_entry_info *entry, off_t offset, int whence, off_t positi return php_stream_seek(fp, temp, SEEK_SET); } -void phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool compress TSRMLS_DC) -{ - char *oldname = NULL, *oldpath = NULL; - char *basename = NULL, *basepath = NULL; - char *newname = NULL, *newpath = NULL; - dtor_func_t save; - - if (phar->flags && compress) { - char *error; - - phar_flush(phar, 0, 0, 0, &error TSRMLS_CC); - if (error) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error); - efree(error); - } - } - - if (!ext) { - if (phar->is_zip) { - if (phar->is_data) { - ext = "zip"; - } else { - ext = "phar.zip"; - } - } else if (phar->is_tar) { - switch (phar->flags) { - case PHAR_FILE_COMPRESSED_GZ: - if (phar->is_data) { - ext = "tar.gz"; - } else { - ext = "phar.tar.gz"; - } - break; - case PHAR_FILE_COMPRESSED_BZ2: - if (phar->is_data) { - ext = "tar.bz2"; - } else { - ext = "phar.tar.bz2"; - } - break; - default: - if (phar->is_data) { - ext = "tar"; - } else { - ext = "phar.tar"; - } - } - } else { - switch (phar->flags) { - case PHAR_FILE_COMPRESSED_GZ: - ext = "phar.gz"; - break; - case PHAR_FILE_COMPRESSED_BZ2: - ext = "phar.bz2"; - break; - default: - ext = "phar"; - } - } - } - - if (ext[0] == '.') { - ++ext; - } - - oldpath = estrndup(phar->fname, phar->fname_len); - oldname = strrchr(phar->fname, '/'); - ++oldname; - - basename = estrndup(oldname, strlen(oldname)); - spprintf(&newname, 0, "%s.%s", strtok(basename, "."), ext); - efree(basename); - - basepath = estrndup(oldpath, strlen(oldpath) - strlen(oldname)); - spprintf(&newpath, 0, "%s%s", basepath, newname); - efree(basepath); - efree(newname); - - if (!phar->is_data) { - if (phar->alias) { - efree(phar->alias); - } - phar->alias = estrndup(newpath, strlen(newpath)); - phar->alias_len = strlen(newpath); - zend_hash_update(&(PHAR_GLOBALS->phar_alias_map), newpath, strlen(newpath), (void*)&phar, sizeof(phar_archive_data*), NULL); - } - - /* remove old guy, add new guy */ - save = PHAR_GLOBALS->phar_fname_map.pDestructor; - /* don't destruct, we are only renaming */ - PHAR_GLOBALS->phar_fname_map.pDestructor = NULL; - zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), oldpath, phar->fname_len); - PHAR_GLOBALS->phar_fname_map.pDestructor = save; - zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), newpath, strlen(newpath), (void*)&phar, sizeof(phar_archive_data*), NULL); - - efree(phar->fname); - - phar->fname = newpath; - phar->fname_len = strlen(newpath); - - unlink(oldpath); - efree(oldpath); -} - /* mount an absolute path or uri to a path internal to the phar archive */ int phar_mount_entry(phar_archive_data *phar, char *filename, int filename_len, char *path, int path_len TSRMLS_DC) { |
