Skip to content

Fixed issue #60953 - #297

Closed
ralphschindler wants to merge 4 commits into
php:masterfrom
ralphschindler:hotfix/bug60953
Closed

ralphschindler wants to merge 4 commits into
php:masterfrom
ralphschindler:hotfix/bug60953

Conversation

@ralphschindler

Copy link
Copy Markdown
Contributor

Altered phar_rename_archive() such that it will look for well known file extensions to strip off when attempting to rename. Not BC safe with regards to PHP-5x.
https://bugs.php.net/bug.php?id=60953

A large part of the motivation here is to allow dotted versions in the name of a phar, and expect the convert*() functions to do minimal processing on the file name, and allow those dotted version names to persist as they should be.

This allows the following to be possible:

$phar = new Phar(__DIR__ . '/package-1.2.3.phar');
$phar['hello.txt'] = 'Hello World';
$phar->stopBuffering();
unset($phar);
$phar = new Phar(__DIR__ . '/package-1.2.3.phar');
$phar->convertToExecutable(Phar::TAR, Phar::GZ);
var_dump(file_exists(__DIR__ . '/package-1.2.3.phar'));
var_dump(file_exists(__DIR__ . '/package-1.2.3.phar.tar.gz'));

@ralphschindler

Copy link
Copy Markdown
Contributor Author

bump.

Comment thread ext/phar/phar_object.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why strndup and not estrndup? And why make a second copy, basename is already temp copy, can't we just put a null in proper place and use it in spprintf then?

@smalyshev

Copy link
Copy Markdown
Contributor

@ralphschindler ping?

@smalyshev

Copy link
Copy Markdown
Contributor

any news?

@ralphschindler

Copy link
Copy Markdown
Contributor Author

Updated addressing your concerns. I will look at the 2 failing tests next, and fix that \t/space formatting issue.

@ralphschindler

Copy link
Copy Markdown
Contributor Author

@smalyshev perhaps we can revisit this for inclusion in 7?

@ralphschindler

Copy link
Copy Markdown
Contributor Author

@smalyshev ^

Altered phar_rename_archive() such that it will look for '.phar'
first, then '.tar' && '.zip' in data phar files before falling
back on finding anything after the first '.' in a file extension
- removed backwards compatibility file name extension code
- fixed all tests and their cleanup to reflect new file name suffixes
Comment thread ext/phar/phar_object.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make the code be far less indented and more readable and more maintainable by using something like:

    int i;
    char *extensions[] = {
        ".phar",
        ".tar",
        ".tgz",
        ".zip"
    };

    int extension_count = sizeof(extensions)/sizeof(extensions[0]);

    for (i=0 ; oldname_ext == NULL && i < extension_count ; i++){
        oldname_ext = strstr(basename, extensions[i]);
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this exact-ish (similar) thing locally as I need to add one more extension (tbz2), will push it tonight. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, Dan's code looks much cleaner.

@smalyshev

Copy link
Copy Markdown
Contributor

Travis is still not happy as it looks.

@ralphschindler

Copy link
Copy Markdown
Contributor Author

I have not pushed any updates yet, which would trigger a new build (I force pushed my last set of changes, which made travis unhappy). I have one other place to fix renaming before it's complete. (See mailing list for details).

@php-pulls

Copy link
Copy Markdown

Comment on behalf of krakjoe at php.net:

Since we have been waiting for this PR to be completed for more than a year, and since this PR has merge conflicts with current master, I'm closing the PR.

If anyone is watching, please take this action as encouragement to open a clean PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants