cvs: pear /File_Archive Archive.php /File_Archive/Archive Reader.php /File_Archive/Archive/Reader Bzip2.php ChangeName.php Concat.php Directory.php
File.php Gzip.php Memory.php Relay.php Tar.php Zip.php /File_Archive/Archive/Writer Multi.php

From: Date: Thu, 26 May 2005 15:57:37 +0000
Subject: cvs: pear /File_Archive Archive.php /File_Archive/Archive Reader.php /File_Archive/Archive/Reader Bzip2.php ChangeName.php Concat.php Directory.php
File.php Gzip.php Memory.php Relay.php Tar.php Zip.php /File_Archive/Archive/Writer Multi.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32132@lists.php.net to get a copy of this message
vincentlascaux Thu May 26 11:57:37 2005 EDT Modified files: /pear/File_Archive Archive.php /pear/File_Archive/Archive Reader.php /pear/File_Archive/Archive/Reader Bzip2.php ChangeName.php Concat.php Directory.php File.php Gzip.php Memory.php Relay.php Tar.php Zip.php /pear/File_Archive/Archive/Writer Multi.php Log: Remove the append function, it won't be available on this release

http://cvs.php.net/diff.php/pear/File_Archive/Archive.php?r1=1.47&r2=1.48&ty=u Index: pear/File_Archive/Archive.php diff -u pear/File_Archive/Archive.php:1.47 pear/File_Archive/Archive.php:1.48 --- pear/File_Archive/Archive.php:1.47 Wed May 25 16:25:27 2005 +++ pear/File_Archive/Archive.php Thu May 26 11:57:36 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.47 2005/05/25 20:25:27 vincentlascaux Exp $ + * @version CVS: $Id: Archive.php,v 1.48 2005/05/26 15:57:36 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -493,34 +493,6 @@ } /** - * Generate a writer to append data to the specified source - * The source will be closed and should no longer be used - * - * To add foo.bar to the existing archive.tar archive, do the following: - * <sample> - * //Append data to a tar archive - * //Do not forget the trailing / (which is here to ask to considere - * //archive.tar as an archive rather than a file) - * File_Archive::extract( - * File_Archive::read('foo.bar'), - * File_Archive::append(File_Archive::read('archive.tar/')), - * ); - * </sample> - * - * Files cannot be appended to nested archives - * - * @param File_Archive_Reader the source where files will be appended - * @return File_Archive_Writer a writer that writes at the end of the source - */ - function append(&$source) - { - if (PEAR::isError($source)) { - return $source; - } - return $source->makeAppendWriter(false); - } - - /** * Removes from a source the files that do not follow a given predicat * * @param File_Archive_Predicate $predicate Only the files for which http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader.php?r1=1.22&r2=1.23&ty=u Index: pear/File_Archive/Archive/Reader.php diff -u pear/File_Archive/Archive/Reader.php:1.22 pear/File_Archive/Archive/Reader.php:1.23 --- pear/File_Archive/Archive/Reader.php:1.22 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader.php Thu May 26 11:57:37 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.22 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Reader.php,v 1.23 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -317,10 +317,25 @@ /** * Returns a writer that will start writing at the current pos in the source * Any data (from current file or any other file) located after current pos - * will be erased. No file will be erased though (so for file and directory - * readers, the file and directory will not be deleted) - * $this->close will be called. $this should not be used until the returned writer - * has been closed + * will be erased. + * For security reasons, calling makeWriter on a directory reader will not erase any file + * though. + * $this->close will be called and after this function the reader is invalid (and + * should no longer be used). + * + * If $fileModif is true, the writer will allow editing the current file (or the + * last file if the end of the archive has been reached) + * Thus it is an error to call makeWriter with fileModif to true if the reader + * has not been opened (no call to next() have been done, or first call to next + * returned false). + * In this case, $seek allows to change the position from where the file must be + * edited + * + * If $fileModif is false, the writer will not allow to edit the current file, and + * the first function call should be new file. The current file will be left unchanged + * If the first function call is writeData, the behaviour is undefined (it + * will generally result in invalid archives). + * In this case, $seek is not used * * Here is how to append a single file to an existing zip archive * <sample> @@ -348,13 +363,16 @@ * @return File_Archive_Writer Writer that appends data to the ressource of this reader, * starting at the current location */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { return PEAR::raiseError("Reader abstract function call (makeWriter)"); } /** + * This is equivalent to move to the end of the archive and calling makeWriter + * * @return a writer that will allow to append files to an existing archive + * @see makeWriter */ function makeAppendWriter($fileModif = true) { http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Bzip2.php?r1=1.8&r2=1.9&ty=u Index: pear/File_Archive/Archive/Reader/Bzip2.php diff -u pear/File_Archive/Archive/Reader/Bzip2.php:1.8 pear/File_Archive/Archive/Reader/Bzip2.php:1.9 --- pear/File_Archive/Archive/Reader/Bzip2.php:1.8 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Bzip2.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Bzip2.php,v 1.8 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Bzip2.php,v 1.9 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -136,7 +136,7 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { require_once "File/Archive/Writer/Bzip2.php"; http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/ChangeName.php?r1=1.13&r2=1.14&ty=u Index: pear/File_Archive/Archive/Reader/ChangeName.php diff -u pear/File_Archive/Archive/Reader/ChangeName.php:1.13 pear/File_Archive/Archive/Reader/ChangeName.php:1.14 --- pear/File_Archive/Archive/Reader/ChangeName.php:1.13 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/ChangeName.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: ChangeName.php,v 1.13 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: ChangeName.php,v 1.14 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -61,15 +61,6 @@ (empty($this->baseName) || empty($name) ? '': '/'). $name; } - - /** - * @see File_Archive_Reader::makeWriter - */ - function makeWriter($seek = 0, $fileModif = true) - { - //TODO: makeWriter - return parent::makeWriter($seek, $fileModif); - } } /** @@ -123,15 +114,6 @@ return $name; } } - - /** - * @see File_Archive_Reader::makeWriter - */ - function makeWriter($seek = 0, $fileModif = true) - { - //TODO: makeWriter - return parent::makeWriter($seek, $fileModif); - } } ?> \ No newline at end of file http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Concat.php?r1=1.10&r2=1.11&ty=u Index: pear/File_Archive/Archive/Reader/Concat.php diff -u pear/File_Archive/Archive/Reader/Concat.php:1.10 pear/File_Archive/Archive/Reader/Concat.php:1.11 --- pear/File_Archive/Archive/Reader/Concat.php:1.10 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Concat.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Concat.php,v 1.10 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Concat.php,v 1.11 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -157,9 +157,9 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { - return $this->source->makeWriter($seek, $fileModif); + return $this->source->makeWriter($fileModif, $seek); } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Directory.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Archive/Archive/Reader/Directory.php diff -u pear/File_Archive/Archive/Reader/Directory.php:1.12 pear/File_Archive/Archive/Reader/Directory.php:1.13 --- pear/File_Archive/Archive/Reader/Directory.php:1.12 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Directory.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Directory.php,v 1.12 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Directory.php,v 1.13 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -135,14 +135,16 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { require_once "File/Archive/Writer/Files.php"; - if ($this->source == null) { + if ($this->source == null || + (!$fileModif && is_a($source, 'File_Archive_Reader_File')) + ) { $writer = new File_Archive_Writer_Files($directory); } else { - $writer = $this->source->makeWriter($seek, $fileModif); + $writer = $this->source->makeWriter($fileModif, $seek); } $toUnlink = array(); http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/File.php?r1=1.17&r2=1.18&ty=u Index: pear/File_Archive/Archive/Reader/File.php diff -u pear/File_Archive/Archive/Reader/File.php:1.17 pear/File_Archive/Archive/Reader/File.php:1.18 --- pear/File_Archive/Archive/Reader/File.php:1.17 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/File.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: File.php,v 1.17 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: File.php,v 1.18 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -184,7 +184,7 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { require_once "File/Archive/Writer/Files.php"; http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Gzip.php?r1=1.17&r2=1.18&ty=u Index: pear/File_Archive/Archive/Reader/Gzip.php diff -u pear/File_Archive/Archive/Reader/Gzip.php:1.17 pear/File_Archive/Archive/Reader/Gzip.php:1.18 --- pear/File_Archive/Archive/Reader/Gzip.php:1.17 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Gzip.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Gzip.php,v 1.17 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Gzip.php,v 1.18 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -137,7 +137,7 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { require_once "File/Archive/Writer/Gzip.php"; http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Memory.php?r1=1.12&r2=1.13&ty=u Index: pear/File_Archive/Archive/Reader/Memory.php diff -u pear/File_Archive/Archive/Reader/Memory.php:1.12 pear/File_Archive/Archive/Reader/Memory.php:1.13 --- pear/File_Archive/Archive/Reader/Memory.php:1.12 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Memory.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Memory.php,v 1.12 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Memory.php,v 1.13 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -154,7 +154,7 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { if ($fileModif == false) { return PEAR::raiseError( @@ -164,7 +164,7 @@ } require_once "File/Archive/Writer/Memory.php"; - $writer = new File_Archive_Writer_Memory($this->memory, $this->offset); + $writer = new File_Archive_Writer_Memory($this->memory, $this->offset + $seek); $this->close(); return $writer; } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Relay.php?r1=1.11&r2=1.12&ty=u Index: pear/File_Archive/Archive/Reader/Relay.php diff -u pear/File_Archive/Archive/Reader/Relay.php:1.11 pear/File_Archive/Archive/Reader/Relay.php:1.12 --- pear/File_Archive/Archive/Reader/Relay.php:1.11 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Relay.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Relay.php,v 1.11 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Relay.php,v 1.12 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -90,9 +90,9 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { - return $this->source->makeWriter($seek, $fileModif); + return $this->source->makeWriter($fileModif, $seek); } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Tar.php?r1=1.18&r2=1.19&ty=u Index: pear/File_Archive/Archive/Reader/Tar.php diff -u pear/File_Archive/Archive/Reader/Tar.php:1.18 pear/File_Archive/Archive/Reader/Tar.php:1.19 --- pear/File_Archive/Archive/Reader/Tar.php:1.18 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Tar.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Tar.php,v 1.18 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Tar.php,v 1.19 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -73,7 +73,7 @@ { $actualLength = min($this->leftLength, $length); $error = $this->source->skip($actualLength); - $length -= $actualLength; + $this->leftLength -= $actualLength; return $error; } @@ -202,17 +202,45 @@ */ function makeWriter($seek = 0, $fileModif = true) { - //TODO: case when $fileModif is true require_once "File/Archive/Writer/Tar.php"; - if ($this->seekToEnd != null) { - $writer = $this->source->makeWriter(- $this->seekToEnd); + if ($fileModif) { + if ($this->seekToEnd != null) { + //Seek before the stat of the last file + $innerSeek = -$this->seekToEnd - $this->currentStat[7] - 512; + if ($this->currentStat[7] % 512 != 0) { + $innerSeek += 512 - $this->currentStat[7] % 512; + } + } else { + //Seek before the stat of the current file + $innerSeek = -$this->currentStat[7] + $this->leftLength - 512; + } } else { - $writer = $this->source->makeWriter(); + if ($this->seekToEnd != null) { + //Seek before the empty header + $innerSeek = -$this->seekToEnd; + } else { + //Seek to the end of the current file + $innerSeek = $this->leftLength; + } + } + + $innerWriter = $this->source->makeWriter($innerSeek); + if (PEAR::isError($innerWriter)) { + return $innerWriter; } + $this->source = null; $this->close(); - return new File_Archive_Writer_Tar(null, $writer); + $writer = new File_Archive_Writer_Tar(null, $writer); + + if ($fileModif) { + //Rewrite the file + + //TODO: inner modification of archives + return PEAR::raiseError("Modification of nested archives not available"); + } + return $writer; } } http://cvs.php.net/diff.php/pear/File_Archive/Archive/Reader/Zip.php?r1=1.16&r2=1.17&ty=u Index: pear/File_Archive/Archive/Reader/Zip.php diff -u pear/File_Archive/Archive/Reader/Zip.php:1.16 pear/File_Archive/Archive/Reader/Zip.php:1.17 --- pear/File_Archive/Archive/Reader/Zip.php:1.16 Wed May 25 16:25:28 2005 +++ pear/File_Archive/Archive/Reader/Zip.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Zip.php,v 1.16 2005/05/25 20:25:28 vincentlascaux Exp $ + * @version CVS: $Id: Zip.php,v 1.17 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -239,9 +239,13 @@ /** * @see File_Archive_Reader::makeWriter */ - function makeWriter($seek = 0, $fileModif = true) + function makeWriter($fileModif = true, $seek = 0) { - //TODO: case when fileModif is true (size of the file changes) + if ($fileModif) { + //TODO: inner modification of archives + return PEAR::raiseError('Modification of nested archives not available'); + } + require_once "File/Archive/Writer/Zip.php"; if ($this->currentFilename == null) { @@ -254,7 +258,7 @@ $seekToEnd = $this->seekToEnd; } - $writer = new File_Archive_Writer_Zip(null, $this->source->makeWriter(- $seekToEnd)); + $writer = new File_Archive_Writer_Zip(null, $this->source->makeWriter(true, - $seekToEnd)); if (!empty($this->files) && $this->seekToEnd == 0) { //Last file will be rewritten http://cvs.php.net/diff.php/pear/File_Archive/Archive/Writer/Multi.php?r1=1.6&r2=1.7&ty=u Index: pear/File_Archive/Archive/Writer/Multi.php diff -u pear/File_Archive/Archive/Writer/Multi.php:1.6 pear/File_Archive/Archive/Writer/Multi.php:1.7 --- pear/File_Archive/Archive/Writer/Multi.php:1.6 Wed Feb 23 15:11:42 2005 +++ pear/File_Archive/Archive/Writer/Multi.php Thu May 26 11:57:37 2005 @@ -25,7 +25,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: Multi.php,v 1.6 2005/02/23 20:11:42 vincentlascaux Exp $ + * @version CVS: $Id: Multi.php,v 1.7 2005/05/26 15:57:37 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -34,7 +34,6 @@ /** * Write to several writers */ -//TODO: check that it's working with PHP4 (worried about the references) class File_Archive_Writer_Multi extends File_Archive_Writer { /**
« previous php.pear.cvs (#32132) next »