Re: cvs: pecl /phar phar.c

From: Date: Sun, 23 Mar 2008 14:57:10 +0000
Subject: Re: cvs: pecl /phar phar.c
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-5253@lists.php.net to get a copy of this message
Steph Fox wrote: > Hi Greg, > > The last time we discussed this, it came to 'a tar is a plain tar > (regardless of INI settings) and cannot be converted by simply adding > a stub'. This is a question of design rather than one of > implementation, and really we should have put down the specs in black > and white. I'd appreciate it if you could take the time to do that > before you disappear on tour, since in the long run it'll mean less > work for both of us. Specs could go on the wiki or in a file in > pecl/phar, but they need to be somewhere accessible. > > Similarly, I still have some unanswered questions about the new > approach to conversion, which means there are areas where I've no idea > what you expect, but I've agreed to code it. Now that sounds like a > disaster waiting to happen if ever I heard one :) (replying to pecl-dev) Hi Steph, The file in question that I was trying to manipulate was named zfapp.phar.tar.php - it's clearly a phar in waiting. Additionally, the only thing that is absolutely required of a phar archive in zip or tar format in order for it to be executable is that it contain "phar" in the name. The way you have designed the conversion/opening code, there was no way to create a tar-based or zip-based phar archive, except via making a phar, and then converting it to a zip/tar, which is awkward at best. The original intention was to enforce naming for phar archives, and to act differently when readonly is enabled. Our goal must be simplicity whenever possible. Basically phar.readonly=1 means we are very strict about enforcing these things: 1) no creation/modification of phar file format archives whatsoever 2) no opening tar/zip-based phar archives with PharData class 3) no opening data tar/zip-based archives with Phar class 4) creation/modification of tar/zip-based archives with PharData class is allowed 5) conversion of phar/tar/zip-based phars to PharData tar/zip without stub/alias is allowed, but the filename cannot contain ".phar" phar.readonly=0 means these criteria: 1) phar file format archives can be created without restriction 2) any format can be converted to any other format, including phar/tar/zip-based phars to PharData tar/zip without stub/alias and vice-versa 3) all phar archives created in tar/zip file format MUST contain "phar" in the filename 4) all pre-existing tar/zip archives modified via Phar class automatically have a stub added if and ONLY if the filename contains "phar" 5) data tar/zip are files without "phar" in the name, and cannot be opened without renaming or conversion from PharData Previous to my commit, there was no way to convert a data-based tar/zip into a phar archive, which was never the intention. In other words, here is the API I'd like to see: Phar->convert() PharData->convert() this method is used to convert a phar archive to any other format, using constants ored together. It returns either a Phar or a PharData object, or throws an exception if conversion is not possible or failed. allowed conversions under phar.readonly=0: phar=>tar phar phar=>compressed tar phar (gz/bz2/uncompressed) phar=>zip phar phar=>tar data (removes alias/stub) phar=>compressed tar data (gz/bz2/uncompressed, removes alias/stub) phar=>zip data (removes alias/stub) phar=>compressed phar (gz/bz2/uncompressed) tar phar=>phar tar phar=>compressed phar (gz/bz2/uncompressed) tar phar=>zip phar tar phar=>compressed tar phar (gz/bz2/uncompressed) tar phar=>tar data (removes alias/stub) tar phar=>compressed tar data (gz/bz2/uncompressed, removes alias/stub) tar phar=>zip data (removes alias/stub) zip phar=>phar zip phar=>compressed phar (gz/bz2/uncompressed) zip phar=>tar phar zip phar=>compressed tar phar (gz/bz2/uncompressed) zip phar=>tar data (removes alias/stub) zip phar=>compressed tar data (gz/bz2/uncompressed, removes alias/stub) zip phar=>zip data (removes alias/stub) tar data=>phar tar data=>compressed phar (gz/bz2/uncompressed) tar data=>zip phar tar data=>tar phar tar data=>compressed tar phar (gz/bz2/uncompressed) tar data=>compressed tar data (gz/bz2/uncompressed) tar data=>zip data zip data=>phar zip data=>compressed phar (gz/bz2/uncompressed) zip data=>tar phar zip data=>compressed tar phar (gz/bz2/uncompressed) zip data=>tar data zip data=>compressed tar data (gz/bz2/uncompressed) allowed conversions under phar.readonly=1 phar=>tar data (removes alias/stub) phar=>compressed tar data (gz/bz2/uncompressed, removes alias/stub) phar=>zip data (removes alias/stub) tar phar=>tar data (removes alias/stub) tar phar=>compressed tar data (gz/bz2/uncompressed, removes alias/stub) tar phar=>zip data (removes alias/stub) zip phar=>tar data (removes alias/stub) zip phar=>compressed tar data (gz/bz2/uncompressed, removes alias/stub) zip phar=>zip data (removes alias/stub) tar data=>compressed tar data (gz/bz2/uncompressed) tar data=>zip data zip data=>tar data zip data=>compressed tar data (gz/bz2/uncompressed) the compressAllFiles*() methods would return to working as they did in 1.X, which is to say they would operate on each file iteratively within the phar archive, in order to compress all files in a zip archive, for instance. They would throw an exception for tar archive because there is no way to compress files within a tar. The sheer number of possible conversions precludes using convertTo*() methods. Simpler is going to be far better here. Constants needed: Phar::PHAR Phar::TAR Phar::ZIP Phar::DATA Phar::GZ Phar::BZ2 Phar::UNCOMPRESS For my example (taking a pre-existing tar with ".phar" in the name and converting it to phar.tar), the code would look something like: <?php copy('zfapp.tgz', 'zfapp.phar.tar.php'); $phar = new Phar('zfapp.phar.tar.php'); $phar->setStub('<?php // blahblah __HALT_COMPILER();'); ?> Here's another example: <?php $pd = new PharData('zfapp.tgz'); $phar = $pd->convert(Phar::TAR); // renames to zfapp.phar.tar.gz - all aspects remain same unless explicitly changed $phar->setStub('<?php // blahblah __HALT_COMPILER();'); ?> and: <?php ini_set('phar.readonly=1'); $phar = new Phar('zfapp.phar.tgz'); $pd = $phar->convert(Phar::DATA); // returns PharData class with no stub/alias, filename zfapp.tgz ?> and finally: <?php $phar = new Phar('zfapp.tar'); // exception - use phardata for data-based phars, and convert() to rename/modify ?> Greg

« previous php.pecl.dev (#5253) next »