Skip to content

Fixed issue #60953 #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Conversation

ralphschindler
Copy link
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
Contributor Author

bump.

oldname_ext = strstr(basename, ".");
}

newname = strndup(basename, (oldname_ext - basename));
Copy link
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
Contributor

@ralphschindler ping?

@smalyshev
Copy link
Contributor

any news?

@ralphschindler
Copy link
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
Contributor Author

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

@ralphschindler
Copy link
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
}
}
}

Copy link
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
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
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
Contributor

Travis is still not happy as it looks.

@ralphschindler
Copy link
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

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