cvs: pear /File_Archive Archive.php /File_Archive/Archive Reader.php /File_Archive/tests test.php

From: Date: Sun, 15 May 2005 00:13:20 +0000
Subject: cvs: pear /File_Archive Archive.php /File_Archive/Archive Reader.php /File_Archive/tests test.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-31861@lists.php.net to get a copy of this message
vincentlascaux Sat May 14 20:13:20 2005 EDT Modified files: /pear/File_Archive Archive.php /pear/File_Archive/Archive Reader.php /pear/File_Archive/tests test.php Log: + Function File_Archive::extract($source, $dest) that simply does $source->extract($dest) and some error checking. It allows to do File_Archive::extract(File_Archive::read('foo'), File_Archive::toOutput()) (no variable creation here) + A bug in File_Archive::readArchive (the wrong source was declared already opened when $sourceOpened == true, with tgz and tbz extensions) + Better error checking for File_Archive_Reader http://cvs.php.net/diff.php/pear/File_Archive/Archive.php?r1=1.38&r2=1.39&ty=u Index: pear/File_Archive/Archive.php diff -u pear/File_Archive/Archive.php:1.38 pear/File_Archive/Archive.php:1.39 --- pear/File_Archive/Archive.php:1.38 Fri May 13 19:32:24 2005 +++ pear/File_Archive/Archive.php Sat May 14 20:13:19 2005 @@ -27,7 +27,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Archive.php,v 1.38 2005/05/13 23:32:24 vincentlascaux Exp $ + * @version CVS: $Id: Archive.php,v 1.39 2005/05/15 00:13:19 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -159,6 +159,10 @@ function readSource(&$source, $URL, $symbolic = null, $uncompression = 0, $directoryDepth = -1) { + if(PEAR::isError($source)) { + return $source; + } + require_once "File/Archive/Reader/Uncompress.php"; require_once "File/Archive/Reader/ChangeName.php"; @@ -382,13 +386,13 @@ { switch($extension) { case 'tgz': - return readArchive('tar', - readArchive('gz', $source), - $sourceOpened); + return File_Archive::readArchive('tar', + File_Archive::readArchive('gz', $source, $sourceOpened) + ); case 'tbz': - return readArchive('tar', - readArchive('bz2', $source), - $sourceOpened); + return File_Archive::readArchive('tar', + File_Archive::readArchive('bz2', $source, $sourceOpened) + ); case 'tar': require_once "File/Archive/Reader/Tar.php"; return new File_Archive_Reader_Tar($source, $sourceOpened); @@ -762,6 +766,9 @@ function toArchive($filename, &$innerWriter, $type = null, $stat = array(), $autoClose = true) { + if (PEAR::isError($innerWriter)) { + return $innerWriter; + } $shortcuts = array("tgz" , "tbz" ); $reals = array("tar.gz", "tar.bz2"); @@ -823,6 +830,25 @@ } return $writer; } + + + /** + * File_Archive::extract($source, $dest) is equivalent to $source->extract($dest) + * If $source is a PEAR error, the error will be returned + * It is thus easier to use this function than $source->extract, since it reduces the number of + * error checking and doesn't force you to define a variable $source + * + * @param File_Archive_Reader $source The source that will be read + * @param File_Archive_Writer $dest Where to copy $source files + * @return null or a PEAR error if an error occured + */ + function extract(&$source, &$dest) + { + if (PEAR::isError($source)) { + return $source; + } + return $source->extract($dest); + } } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader.php?r1=1.17&r2=1.18&ty=u Index: pear/File_Archive/Archive/Reader.php diff -u pear/File_Archive/Archive/Reader.php:1.17 pear/File_Archive/Archive/Reader.php:1.18 --- pear/File_Archive/Archive/Reader.php:1.17 Fri May 13 19:32:25 2005 +++ pear/File_Archive/Archive/Reader.php Sat May 14 20:13:20 2005 @@ -27,7 +27,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Reader.php,v 1.17 2005/05/13 23:32:25 vincentlascaux Exp $ + * @version CVS: $Id: Reader.php,v 1.18 2005/05/15 00:13:20 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -191,6 +191,10 @@ */ function sendData(&$writer, $bufferSize = 102400) { + if (PEAR::isError($writer)) { + return $writer; + } + $filename = $this->getDataFilename(); if ($filename !== NULL) { $error = $writer->writeFile($filename); @@ -221,6 +225,10 @@ */ function extract(&$writer, $autoClose = true, $bufferSize = 102400) { + if (PEAR::isError($writer)) { + return $writer; + } + while (($error = $this->next()) === true) { $error = $writer->newFile( $this->getFilename(), @@ -257,6 +265,10 @@ function extractFile($filename, &$writer, $autoClose = true, $bufferSize = 102400) { + if (PEAR::isError($writer)) { + return $writer; + } + if (($error = $this->select($filename)) === true) { $result = $this->sendData($writer, $bufferSize); if (!PEAR::isError($result)) { http://cvs.php.net/diff.php/pear/File_Archive/tests/test.php?r1=1.28&r2=1.29&ty=u Index: pear/File_Archive/tests/test.php diff -u pear/File_Archive/tests/test.php:1.28 pear/File_Archive/tests/test.php:1.29 --- pear/File_Archive/tests/test.php:1.28 Fri May 6 16:19:50 2005 +++ pear/File_Archive/tests/test.php Sat May 14 20:13:20 2005 @@ -287,8 +287,10 @@ } function testDirectories() { - $source = File_Archive::read('../Archive'); - $source->extract(File_Archive::toArchive('up.tbz', File_Archive::toFiles())); + File_Archive::extract( + File_Archive::read('../Archive'), + File_Archive::toArchive('up.tbz', File_Archive::toFiles()) + ); $source = File_Archive::read('up.tbz/'); $appendedData = File_Archive::read('test.php');

« previous php.pear.cvs (#31861) next »