Re: cvs: pear-core /Archive Tar.php
| From: | bertrand Gugger | Date: | Sun, 20 Nov 2005 16:48:16 +0000 |
| Subject: | Re: cvs: pear-core /Archive Tar.php | ||
| References: | 1 | Groups: | php.pear.cvs |
| Request: | Send a blank email to pear-cvs+get-36391@lists.php.net to get a copy of this message | ||
Bonjour,
What do you mean synchro ?
If it's really the same package , it should be only.
(as Getopt and "rooted" packages)
Synchros do not work
The diff is awfull here.
is it a blank problem ? I will try to diff -b
a+
--
toggg
Vincent Blavet wrote:
> vblavet Sun Nov 20 09:11:13 2005 EDT
>
> Modified files:
> /pear-core/Archive Tar.php
> Log:
> - Syncho with pear/Archive_Tar/Archive/Tar.php 1.33
>
>
>
> ------------------------------------------------------------------------
>
> http://cvs.php.net/diff.php/pear-core/Archive/Tar.php?r1=1.21&r2=1.22&ty=u
> Index: pear-core/Archive/Tar.php
> diff -u pear-core/Archive/Tar.php:1.21 pear-core/Archive/Tar.php:1.22
> --- pear-core/Archive/Tar.php:1.21 Tue Nov 1 22:49:06 2005
> +++ pear-core/Archive/Tar.php Sun Nov 20 09:11:10 2005
> @@ -13,18 +13,31 @@
> // | obtain it through the world-wide-web, please send a note to |
> // | license@php.net so we can mail you a copy immediately. |
> // +----------------------------------------------------------------------+
> -// | Author: Vincent Blavet <vincent@blavet.net> |
> +// | Author: Vincent Blavet <vincent@phpconcept.net> |
> // +----------------------------------------------------------------------+
> //
> -// $Id: Tar.php,v 1.21 2005/11/02 03:49:06 cellog Exp $
> +// +----------------------------------------------------------------------+
> +// | WARNING : |
> +// | This file is a copy of pear/Archive_Tar/Archive/Tar.php |
> +// | NEVER MODIFY THIS FILE DIRECTLY WITHOUT MODIFYING THE REFERENCE FILE |
> +// | If you modify this file without synchronizing with |
> +// | pear/Archive_Tar/Archive/Tar.php, when the package will be upgraded |
> +// | with "pear upgrade Archive_Tar", it may result in software/bug |
> +// | regression. |
> +// +----------------------------------------------------------------------+
> +//
> +// $Id: Tar.php,v 1.22 2005/11/20 14:11:10 vblavet Exp $
>
> require_once 'PEAR.php';
>
> +
> +define ('ARCHIVE_TAR_ATT_SEPARATOR', 90001);
> +
> /**
> * Creates a (compressed) Tar archive
> *
> -* @author Vincent Blavet <vincent@blavet.net>
> -* @version $Revision: 1.21 $
> +* @author Vincent Blavet <vincent@phpconcept.net>
> +* @version $Revision: 1.22 $
> * @package Archive
> */
> class Archive_Tar extends PEAR
> @@ -45,6 +58,11 @@
> var $_compress_type='none';
>
> /**
> + * @var string Explode separator
> + */
> + var $_separator=' ';
> +
> + /**
> * @var file descriptor
> */
> var $_file=0;
> @@ -74,7 +92,7 @@
> $this->PEAR();
> $this->_compress = false;
> $this->_compress_type = 'none';
> - if ($p_compress === null) {
> + if (($p_compress === null) || ($p_compress == '')) {
> if (@file_exists($p_tarname)) {
> if ($fp = @fopen($p_tarname, "rb")) {
> // look for gzip magic cookie
> @@ -102,12 +120,16 @@
> }
> }
> } else {
> - if (($p_compress == true) || ($p_compress == 'gz')) {
> + if (($p_compress === true) || ($p_compress == 'gz')) {
> $this->_compress = true;
> $this->_compress_type = 'gz';
> } else if ($p_compress == 'bz2') {
> $this->_compress = true;
> $this->_compress_type = 'bz2';
> + } else {
> + die("Unsupported compression type '$p_compress'\n".
> + "Supported types are 'gz' and 'bz2'.\n");
> + return false;
> }
> }
> $this->_tarname = $p_tarname;
> @@ -156,8 +178,9 @@
> * sub-directories are also added.
> * See also createModify() method for more details.
> *
> - * @param array $p_filelist An array of filenames and directory names, or a single
> - * string with names separated by a single blank space.
> + * @param array $p_filelist An array of filenames and directory names, or a
> + * single string with names separated by a single
> + * blank space.
> * @return true on success, false on error.
> * @see createModify()
> * @access public
> @@ -177,8 +200,9 @@
> * even if a file with the same name is already archived.
> * See also createModify() method for more details.
> *
> - * @param array $p_filelist An array of filenames and directory names, or a single
> - * string with names separated by a single blank space.
> + * @param array $p_filelist An array of filenames and directory names, or a
> + * single string with names separated by a single
> + * blank space.
> * @return true on success, false on error.
> * @see createModify()
> * @access public
> @@ -236,13 +260,15 @@
> * for extraction in a different path than the origin files are.
> * See also addModify() method for file adding properties.
> *
> - * @param array $p_filelist An array of filenames and directory names, or a single
> - * string with names separated by a single blank space.
> - * @param string $p_add_dir A string which contains a path to be added to the
> - * memorized path of each element in the list.
> - * @param string $p_remove_dir A string which contains a path to be removed from
> - * the memorized path of each element in the list, when
> - * relevant.
> + * @param array $p_filelist An array of filenames and directory names,
> + * or a single string with names separated by
> + * a single blank space.
> + * @param string $p_add_dir A string which contains a path to be added
> + * to the memorized path of each element in
> + * the list.
> + * @param string $p_remove_dir A string which contains a path to be
> + * removed from the memorized path of each
> + * element in the list, when relevant.
> * @return boolean true on success, false on error.
> * @access public
> * @see addModify()
> @@ -258,7 +284,7 @@
> if (is_array($p_filelist))
> $v_list = $p_filelist;
> elseif (is_string($p_filelist))
> - $v_list = explode(" ", $p_filelist);
> + $v_list = explode($this->_separator, $p_filelist);
> else {
> $this->_cleanFile();
> $this->_error('Invalid file list');
> @@ -306,12 +332,15 @@
> * If a file/dir is not readable the file/dir is ignored. However an
> * error text is send to PEAR error.
> *
> - * @param array $p_filelist An array of filenames and directory names, or a single
> - * string with names separated by a single blank space.
> - * @param string $p_add_dir A string which contains a path to be added to the
> - * memorized path of each element in the list.
> - * @param string $p_remove_dir A string which contains a path to be removed from
> - * the memorized path of each element in the list, when
> + * @param array $p_filelist An array of filenames and directory
> + * names, or a single string with names
> + * separated by a single blank space.
> + * @param string $p_add_dir A string which contains a path to be
> + * added to the memorized path of each
> + * element in the list.
> + * @param string $p_remove_dir A string which contains a path to be
> + * removed from the memorized path of
> + * each element in the list, when
> * relevant.
> * @return true on success, false on error.
> * @access public
> @@ -320,13 +349,14 @@
> {
> $v_result = true;
>
> - if (!@is_file($this->_tarname))
> - $v_result = $this->createModify($p_filelist, $p_add_dir, $p_remove_dir);
> + if (!$this->_isArchive())
> + $v_result = $this->createModify($p_filelist, $p_add_dir,
> + $p_remove_dir);
> else {
> if (is_array($p_filelist))
> $v_list = $p_filelist;
> elseif (is_string($p_filelist))
> - $v_list = explode(" ", $p_filelist);
> + $v_list = explode($this->_separator, $p_filelist);
> else {
> $this->_error('Invalid file list');
> return false;
> @@ -345,9 +375,11 @@
> * end of the existing archive. If the archive does not yet exists it
> * is created.
> *
> - * @param string $p_filename A string which contains the full filename path
> - * that will be associated with the string.
> - * @param string $p_string The content of the file added in the archive.
> + * @param string $p_filename A string which contains the full
> + * filename path that will be associated
> + * with the string.
> + * @param string $p_string The content of the file added in
> + * the archive.
> * @return true on success, false on error.
> * @access public
> */
> @@ -355,7 +387,7 @@
> {
> $v_result = true;
>
> - if (!@is_file($this->_tarname)) {
> + if (!$this->_isArchive()) {
> if (!$this->_openWrite()) {
> return false;
> }
> @@ -401,10 +433,11 @@
> * is returned. However the result can be a partial extraction that may
> * need to be manually cleaned.
> *
> - * @param string $p_path The path of the directory where the files/dir need to by
> - * extracted.
> - * @param string $p_remove_path Part of the memorized path that can be removed if
> - * present at the beginning of the file/dir path.
> + * @param string $p_path The path of the directory where the
> + * files/dir need to by extracted.
> + * @param string $p_remove_path Part of the memorized path that can be
> + * removed if present at the beginning of
> + * the file/dir path.
> * @return boolean true on success, false on error.
> * @access public
> * @see extractList()
> @@ -415,7 +448,8 @@
> $v_list_detail = array();
>
> if ($v_result = $this->_openRead()) {
> - $v_result = $this->_extractList($p_path, $v_list_detail, "complete",
0, $p_remove_path);
> + $v_result = $this->_extractList($p_path, $v_list_detail,
> + "complete", 0, $p_remove_path);
> $this->_close();
> }
>
> @@ -451,12 +485,14 @@
> * in the directory indicated by the optional $p_path parameter.
> * If indicated the $p_remove_path can be used in the same way as it is
> * used in extractModify() method.
> - * @param array $p_filelist An array of filenames and directory names, or a single
> - * string with names separated by a single blank space.
> - * @param string $p_path The path of the directory where the files/dir need to by
> - * extracted.
> - * @param string $p_remove_path Part of the memorized path that can be removed if
> - * present at the beginning of the file/dir path.
> + * @param array $p_filelist An array of filenames and directory names,
> + * or a single string with names separated
> + * by a single blank space.
> + * @param string $p_path The path of the directory where the
> + * files/dir need to by extracted.
> + * @param string $p_remove_path Part of the memorized path that can be
> + * removed if present at the beginning of
> + * the file/dir path.
> * @return true on success, false on error.
> * @access public
> * @see extractModify()
> @@ -469,14 +505,15 @@
> if (is_array($p_filelist))
> $v_list = $p_filelist;
> elseif (is_string($p_filelist))
> - $v_list = explode(" ", $p_filelist);
> + $v_list = explode($this->_separator, $p_filelist);
> else {
> $this->_error('Invalid string list');
> return false;
> }
>
> if ($v_result = $this->_openRead()) {
> - $v_result = $this->_extractList($p_path, $v_list_detail, "partial",
$v_list, $p_remove_path);
> + $v_result = $this->_extractList($p_path, $v_list_detail, "partial",
> + $v_list, $p_remove_path);
> $this->_close();
> }
>
> @@ -484,6 +521,60 @@
> }
> // }}}
>
> + // {{{ setAttribute()
> + /**
> + * This method set specific attributes of the archive. It uses a variable
> + * list of parameters, in the format attribute code + attribute values :
> + * $arch->setAttribute(ARCHIVE_TAR_ATT_SEPARATOR, ',');
> + * @param mixed $argv variable list of attributes and values
> + * @return true on success, false on error.
> + * @access public
> + */
> + function setAttribute()
> + {
> + $v_result = true;
> +
> + // ----- Get the number of variable list of arguments
> + if (($v_size = func_num_args()) == 0) {
> + return true;
> + }
> +
> + // ----- Get the arguments
> + $v_att_list = &func_get_args();
> +
> + // ----- Read the attributes
> + $i=0;
> + while ($i<$v_size) {
> +
> + // ----- Look for next option
> + switch ($v_att_list[$i]) {
> + // ----- Look for options that request a string value
> + case ARCHIVE_TAR_ATT_SEPARATOR :
> + // ----- Check the number of parameters
> + if (($i+1) >= $v_size) {
> + $this->_error('Invalid number of parameters for '
> + .'attribute ARCHIVE_TAR_ATT_SEPARATOR');
> + return false;
> + }
> +
> + // ----- Get the value
> + $this->_separator = $v_att_list[$i+1];
> + $i++;
> + break;
> +
> + default :
> + $this->_error('Unknow attribute code
'.$v_att_list[$i].'');
> + return false;
> + }
> +
> + // ----- Next attribute
> + $i++;
> + }
> +
> + return $v_result;
> + }
> + // }}}
> +
> // {{{ _error()
> function _error($p_message)
> {
> @@ -500,20 +591,33 @@
> }
> // }}}
>
> + // {{{ _isArchive()
> + function _isArchive($p_filename=NULL)
> + {
> + if ($p_filename == NULL) {
> + $p_filename = $this->_tarname;
> + }
> + clearstatcache();
> + return @is_file($p_filename);
> + }
> + // }}}
> +
> // {{{ _openWrite()
> function _openWrite()
> {
> if ($this->_compress_type == 'gz')
> - $this->_file = @gzopen($this->_tarname, "wb");
> + $this->_file = @gzopen($this->_tarname, "wb9");
> else if ($this->_compress_type == 'bz2')
> $this->_file = @bzopen($this->_tarname, "wb");
> else if ($this->_compress_type == 'none')
> $this->_file = @fopen($this->_tarname, "wb");
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
>
> if ($this->_file == 0) {
> - $this->_error('Unable to open in write mode
\''.$this->_tarname.'\'');
> + $this->_error('Unable to open in write mode \''
> + .$this->_tarname.'\'');
> return false;
> }
>
> @@ -530,12 +634,14 @@
> if ($this->_temp_tarname == '') {
> $this->_temp_tarname = uniqid('tar').'.tmp';
> if (!$v_file_from = @fopen($this->_tarname, 'rb')) {
> - $this->_error('Unable to open in read mode
\''.$this->_tarname.'\'');
> + $this->_error('Unable to open in read mode \''
> + .$this->_tarname.'\'');
> $this->_temp_tarname = '';
> return false;
> }
> if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) {
> - $this->_error('Unable to open in write mode
\''.$this->_temp_tarname.'\'');
> + $this->_error('Unable to open in write mode \''
> + .$this->_temp_tarname.'\'');
> $this->_temp_tarname = '';
> return false;
> }
> @@ -559,7 +665,8 @@
> else if ($this->_compress_type == 'none')
> $this->_file = @fopen($v_filename, "rb");
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
>
> if ($this->_file == 0) {
> $this->_error('Unable to open in read mode
\''.$v_filename.'\'');
> @@ -580,10 +687,12 @@
> else if ($this->_compress_type == 'none')
> $this->_file = @fopen($this->_tarname, "r+b");
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
>
> if ($this->_file == 0) {
> - $this->_error('Unable to open in read/write mode
\''.$this->_tarname.'\'');
> + $this->_error('Unable to open in read/write mode \''
> + .$this->_tarname.'\'');
> return false;
> }
>
> @@ -594,7 +703,8 @@
> // {{{ _close()
> function _close()
> {
> - if (isset($this->_file)) {
> + //if (isset($this->_file)) {
> + if (is_resource($this->_file)) {
> if ($this->_compress_type == 'gz')
> @gzclose($this->_file);
> else if ($this->_compress_type == 'bz2')
> @@ -602,7 +712,8 @@
> else if ($this->_compress_type == 'none')
> @fclose($this->_file);
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
>
> $this->_file = 0;
> }
> @@ -641,7 +752,7 @@
> // {{{ _writeBlock()
> function _writeBlock($p_binary_data, $p_len=null)
> {
> - if ($this->_file) {
> + if (is_resource($this->_file)) {
> if ($p_len === null) {
> if ($this->_compress_type == 'gz')
> @gzputs($this->_file, $p_binary_data);
> @@ -650,7 +761,8 @@
> else if ($this->_compress_type == 'none')
> @fputs($this->_file, $p_binary_data);
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
> } else {
> if ($this->_compress_type == 'gz')
> @gzputs($this->_file, $p_binary_data, $p_len);
> @@ -659,7 +771,8 @@
> else if ($this->_compress_type == 'none')
> @fputs($this->_file, $p_binary_data, $p_len);
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
>
> }
> }
> @@ -668,13 +781,10 @@
> // }}}
>
> // {{{ _readBlock()
> - function _readBlock($p_len=null)
> + function _readBlock()
> {
> $v_block = null;
> - if ($this->_file) {
> - if ($p_len === null)
> - $p_len = 512;
> -
> + if (is_resource($this->_file)) {
> if ($this->_compress_type == 'gz')
> $v_block = @gzread($this->_file, 512);
> else if ($this->_compress_type == 'bz2')
> @@ -682,8 +792,8 @@
> else if ($this->_compress_type == 'none')
> $v_block = @fread($this->_file, 512);
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> -
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
> }
> return $v_block;
> }
> @@ -692,12 +802,13 @@
> // {{{ _jumpBlock()
> function _jumpBlock($p_len=null)
> {
> - if ($this->_file) {
> + if (is_resource($this->_file)) {
> if ($p_len === null)
> $p_len = 1;
>
> - if ($this->_compress_type == 'gz')
> - @gzseek($this->_file, @gztell($this->_file)+($p_len*512));
> + if ($this->_compress_type == 'gz') {
> + @gzseek($this->_file, gztell($this->_file)+($p_len*512));
> + }
> else if ($this->_compress_type == 'bz2') {
> // ----- Replace missing bztell() and bzseek()
> for ($i=0; $i<$p_len; $i++)
> @@ -705,7 +816,8 @@
> } else if ($this->_compress_type == 'none')
> @fseek($this->_file, ftell($this->_file)+($p_len*512));
> else
> - $this->_error('Unknown or missing compression type
('.$this->_compress_type.')');
> + $this->_error('Unknown or missing compression type ('
> + .$this->_compress_type.')');
>
> }
> return true;
> @@ -715,10 +827,11 @@
> // {{{ _writeFooter()
> function _writeFooter()
> {
> - if ($this->_file) {
> + if (is_resource($this->_file)) {
> // ----- Write the last 0 filled block for end of archive
> $v_binary_data = pack("a512", '');
> $this->_writeBlock($v_binary_data);
> + $this->_writeBlock($v_binary_data);
> }
> return true;
> }
> @@ -742,8 +855,10 @@
> if (sizeof($p_list) == 0)
> return true;
>
> - for ($j=0; ($j<count($p_list)) && ($v_result); $j++) {
> - $v_filename = $p_list[$j];
> + foreach ($p_list as $v_filename) {
> + if (!$v_result) {
> + break;
> + }
>
> // ----- Skip the current tar name
> if ($v_filename == $this->_tarname)
> @@ -766,15 +881,17 @@
> $this->_warning("Directory '$v_filename' can not be
read");
> continue;
> }
> - $p_hitem = readdir($p_hdir); // '.' directory
> - $p_hitem = readdir($p_hdir); // '..' directory
> while (false !== ($p_hitem = readdir($p_hdir))) {
> + if (($p_hitem != '.') && ($p_hitem != '..')) {
> if ($v_filename != ".")
> $p_temp_list[0] = $v_filename.'/'.$p_hitem;
> else
> $p_temp_list[0] = $p_hitem;
>
> - $v_result = $this->_addList($p_temp_list, $p_add_dir, $p_remove_dir);
> + $v_result = $this->_addList($p_temp_list,
> + $p_add_dir,
> + $p_remove_dir);
> + }
> }
>
> unset($p_temp_list);
> @@ -823,9 +940,10 @@
>
> $v_stored_filename = $this->_pathReduction($v_stored_filename);
>
> - if (is_file($p_filename)) {
> + if ($this->_isArchive($p_filename)) {
> if (($v_file = @fopen($p_filename, "rb")) == 0) {
> - $this->_warning("Unable to open file '$p_filename' in binary
read mode");
> + $this->_warning("Unable to open file '".$p_filename
> + ."' in binary read mode");
> return true;
> }
>
> @@ -865,7 +983,8 @@
> // ----- Calculate the stored filename
> $p_filename = $this->_translateWinPath($p_filename, false);;
>
> - if (!$this->_writeHeaderBlock($p_filename, strlen($p_string), 0, 0, "", 0,
0))
> + if (!$this->_writeHeaderBlock($p_filename, strlen($p_string),
> + time(), 384, "", 0, 0))
> return false;
>
> $i=0;
> @@ -922,8 +1041,13 @@
>
> $v_prefix = '';
>
> - $v_binary_data_first = pack("a100a8a8a8a12A12", $v_reduce_filename,
$v_perms, $v_uid, $v_gid, $v_size, $v_mtime);
> - $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $v_typeflag,
$v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix,
'');
> + $v_binary_data_first = pack("a100a8a8a8a12A12",
> + $v_reduce_filename, $v_perms, $v_uid,
> + $v_gid, $v_size, $v_mtime);
> + $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12",
> + $v_typeflag, $v_linkname, $v_magic,
> + $v_version, $v_uname, $v_gname,
> + $v_devmajor, $v_devminor, $v_prefix, '');
>
> // ----- Calculate the checksum
> $v_checksum = 0;
> @@ -953,7 +1077,8 @@
> // }}}
>
> // {{{ _writeHeaderBlock()
> - function _writeHeaderBlock($p_filename, $p_size, $p_mtime=0, $p_perms=0,
$p_type='', $p_uid=0, $p_gid=0)
> + function _writeHeaderBlock($p_filename, $p_size, $p_mtime=0, $p_perms=0,
> + $p_type='', $p_uid=0, $p_gid=0)
> {
> $p_filename = $this->_pathReduction($p_filename);
>
> @@ -990,8 +1115,13 @@
>
> $v_prefix = '';
>
> - $v_binary_data_first = pack("a100a8a8a8a12A12", $p_filename, $v_perms,
$v_uid, $v_gid, $v_size, $v_mtime);
> - $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $p_type,
$v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix,
'');
> + $v_binary_data_first = pack("a100a8a8a8a12A12",
> + $p_filename, $v_perms, $v_uid, $v_gid,
> + $v_size, $v_mtime);
> + $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12",
> + $p_type, $v_linkname, $v_magic,
> + $v_version, $v_uname, $v_gname,
> + $v_devmajor, $v_devminor, $v_prefix, '');
>
> // ----- Calculate the checksum
> $v_checksum = 0;
> @@ -1043,8 +1173,12 @@
>
> $v_prefix = '';
>
> - $v_binary_data_first = pack("a100a8a8a8a12A12", '././@LongLink',
0, 0, 0, $v_size, 0);
> - $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $v_typeflag,
$v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix,
'');
> + $v_binary_data_first = pack("a100a8a8a8a12A12",
> + '././@LongLink', 0, 0, 0, $v_size, 0);
> + $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12",
> + $v_typeflag, $v_linkname, $v_magic,
> + $v_version, $v_uname, $v_gname,
> + $v_devmajor, $v_devminor, $v_prefix, '');
>
> // ----- Calculate the checksum
> $v_checksum = 0;
> @@ -1106,7 +1240,10 @@
> for ($i=156; $i<512; $i++)
> $v_checksum+=ord(substr($v_binary_data,$i,1));
>
> - $v_data =
unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor",
$v_binary_data);
> + $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/"
> + ."a8checksum/a1typeflag/a100link/a6magic/a2version/"
> + ."a32uname/a32gname/a8devmajor/a8devminor",
> + $v_binary_data);
>
> // ----- Extract the checksum
> $v_header['checksum'] = OctDec(trim($v_data['checksum']));
> @@ -1117,7 +1254,9 @@
> if (($v_checksum == 256) && ($v_header['checksum'] == 0))
> return true;
>
> - $this->_error('Invalid checksum for file
"'.$v_data['filename'].'" : '.$v_checksum.' calculated,
'.$v_header['checksum'].' expected');
> + $this->_error('Invalid checksum for file
"'.$v_data['filename']
> + .'" : '.$v_checksum.' calculated, '
> + .$v_header['checksum'].' expected');
> return false;
> }
>
> @@ -1131,7 +1270,8 @@
> if (($v_header['typeflag'] = $v_data['typeflag']) ==
"5") {
> $v_header['size'] = 0;
> }
> - /* ----- All these fields are removed form the header because they do not carry
interesting info
> + /* ----- All these fields are removed form the header because
> + they do not carry interesting info
> $v_header[link] = trim($v_data[link]);
> $v_header[magic] = trim($v_data[magic]);
> $v_header[version] = trim($v_data[version]);
> @@ -1199,7 +1339,8 @@
>
> if ($v_header['filename'] == $p_filename) {
> if ($v_header['typeflag'] == "5") {
> - $this->_error('Unable to extract in string a directory entry
{'.$v_header['filename'].'}');
> + $this->_error('Unable to extract in string a directory '
> + .'entry {'.$v_header['filename'].'}');
> return NULL;
> } else {
> $n = floor($v_header['size']/512);
> @@ -1208,7 +1349,8 @@
> }
> if (($v_header['size'] % 512) != 0) {
> $v_content = $this->_readBlock();
> - $v_result_str .= substr($v_content, 0, ($v_header['size'] %
512));
> + $v_result_str .= substr($v_content, 0,
> + ($v_header['size'] % 512));
> }
> return $v_result_str;
> }
> @@ -1222,7 +1364,8 @@
> // }}}
>
> // {{{ _extractList()
> - function _extractList($p_path, &$p_list_detail, $p_mode, $p_file_list, $p_remove_path)
> + function _extractList($p_path, &$p_list_detail, $p_mode,
> + $p_file_list, $p_remove_path)
> {
> $v_result=true;
> $v_nb = 0;
> @@ -1230,7 +1373,8 @@
> $v_listing = false;
>
> $p_path = $this->_translateWinPath($p_path, false);
> - if ($p_path == '' || (substr($p_path, 0, 1) != '/' &&
substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) {
> + if ($p_path == '' || (substr($p_path, 0, 1) != '/'
> + && substr($p_path, 0, 3) != "../" && !strpos($p_path,
':'))) {
> $p_path = "./".$p_path;
> }
> $p_remove_path = $this->_translateWinPath($p_remove_path);
> @@ -1260,7 +1404,7 @@
>
> clearstatcache();
>
> - While (strlen($v_binary_data = $this->_readBlock()) != 0)
> + while (strlen($v_binary_data = $this->_readBlock()) != 0)
> {
> $v_extract_file = FALSE;
> $v_extraction_stopped = 0;
> @@ -1268,8 +1412,9 @@
> if (!$this->_readHeader($v_binary_data, $v_header))
> return false;
>
> - if ($v_header['filename'] == '')
> + if ($v_header['filename'] == '') {
> continue;
> + }
>
> // ----- Look for long filename
> if ($v_header['typeflag'] == 'L') {
> @@ -1285,7 +1430,9 @@
> // ----- Look if it is a directory
> if (substr($p_file_list[$i], -1) == '/') {
> // ----- Look if the directory is in the filename path
> - if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
&& (substr($v_header['filename'], 0, strlen($p_file_list[$i])) ==
$p_file_list[$i])) {
> + if ((strlen($v_header['filename']) > strlen($p_file_list[$i]))
> + && (substr($v_header['filename'], 0, strlen($p_file_list[$i]))
> + == $p_file_list[$i])) {
> $v_extract_file = TRUE;
> break;
> }
> @@ -1305,8 +1452,10 @@
> if (($v_extract_file) && (!$v_listing))
> {
> if (($p_remove_path != '')
> - && (substr($v_header['filename'], 0, $p_remove_path_size) ==
$p_remove_path))
> - $v_header['filename'] = substr($v_header['filename'],
$p_remove_path_size);
> + && (substr($v_header['filename'], 0, $p_remove_path_size)
> + == $p_remove_path))
> + $v_header['filename'] = substr($v_header['filename'],
> + $p_remove_path_size);
> if (($p_path != './') && ($p_path != '/')) {
> while (substr($p_path, -1) == '/')
> $p_path = substr($p_path, 0, strlen($p_path)-1);
> @@ -1317,16 +1466,21 @@
> $v_header['filename'] =
$p_path.'/'.$v_header['filename'];
> }
> if (file_exists($v_header['filename'])) {
> - if ((@is_dir($v_header['filename'])) &&
($v_header['typeflag'] == '')) {
> - $this->_error('File '.$v_header['filename'].' already
exists as a directory');
> + if ( (@is_dir($v_header['filename']))
> + && ($v_header['typeflag'] == '')) {
> + $this->_error('File '.$v_header['filename']
> + .' already exists as a directory');
> return false;
> }
> - if ((is_file($v_header['filename'])) &&
($v_header['typeflag'] == "5")) {
> - $this->_error('Directory '.$v_header['filename'].'
already exists as a file');
> + if ( ($this->_isArchive($v_header['filename']))
> + && ($v_header['typeflag'] == "5")) {
> + $this->_error('Directory '.$v_header['filename']
> + .' already exists as a file');
> return false;
> }
> if (!is_writeable($v_header['filename'])) {
> - $this->_error('File '.$v_header['filename'].' already
exists and is write protected');
> + $this->_error('File '.$v_header['filename']
> + .' already exists and is write protected');
> return false;
> }
> if (filemtime($v_header['filename']) > $v_header['mtime']) {
> @@ -1335,7 +1489,10 @@
> }
>
> // ----- Check the directory availability and create it if necessary
> - elseif (($v_result = $this->_dirCheck(($v_header['typeflag'] ==
"5"?$v_header['filename']:dirname($v_header['filename'])))) != 1) {
> + elseif (($v_result
> + = $this->_dirCheck(($v_header['typeflag'] == "5"
> + ?$v_header['filename']
> + :dirname($v_header['filename'])))) != 1) {
> $this->_error('Unable to create path for
'.$v_header['filename']);
> return false;
> }
> @@ -1344,13 +1501,15 @@
> if ($v_header['typeflag'] == "5") {
> if (!@file_exists($v_header['filename'])) {
> if (!@mkdir($v_header['filename'], 0777)) {
> - $this->_error('Unable to create directory
{'.$v_header['filename'].'}');
> + $this->_error('Unable to create directory {'
> + .$v_header['filename'].'}');
> return false;
> }
> }
> } else {
> if (($v_dest_file = @fopen($v_header['filename'], "wb")) ==
0) {
> - $this->_error('Error while opening
{'.$v_header['filename'].'} in write binary mode');
> + $this->_error('Error while opening
{'.$v_header['filename']
> + .'} in write binary mode');
> return false;
> } else {
> $n = floor($v_header['size']/512);
> @@ -1377,7 +1536,11 @@
> // ----- Check the file size
> clearstatcache();
> if (filesize($v_header['filename']) != $v_header['size']) {
> - $this->_error('Extracted file
'.$v_header['filename'].' does not have the correct file size
\''.filesize($v_filename).'\' ('.$v_header['size'].'
expected). Archive may be corrupted.');
> + $this->_error('Extracted file '.$v_header['filename']
> + .' does not have the correct file size \''
> + .filesize($v_header['filename'])
> + .'\' ('.$v_header['size']
> + .' expected). Archive may be corrupted.');
> return false;
> }
> }
> @@ -1397,7 +1560,8 @@
>
> if ($v_listing || $v_extract_file || $v_extraction_stopped) {
> // ----- Log extracted files
> - if (($v_file_dir = dirname($v_header['filename'])) ==
$v_header['filename'])
> + if (($v_file_dir = dirname($v_header['filename']))
> + == $v_header['filename'])
> $v_file_dir = '';
> if ((substr($v_header['filename'], 0, 1) == '/') &&
($v_file_dir == ''))
> $v_file_dir = '/';
> @@ -1420,7 +1584,9 @@
> $this->_close();
>
> if (!@rename($this->_tarname, $this->_tarname.".tmp")) {
> - $this->_error('Error while renaming
\''.$this->_tarname.'\' to temporary file
\''.$this->_tarname.'.tmp\'');
> + $this->_error('Error while renaming \''.$this->_tarname
> + .'\' to temporary file \''.$this->_tarname
> + .'.tmp\'');
> return false;
> }
>
> @@ -1430,7 +1596,8 @@
> $v_temp_tar = @bzopen($this->_tarname.".tmp", "rb");
>
> if ($v_temp_tar == 0) {
> - $this->_error('Unable to open file
\''.$this->_tarname.'.tmp\' in binary read mode');
> + $this->_error('Unable to open file \''.$this->_tarname
> + .'.tmp\' in binary read mode');
> @rename($this->_tarname.".tmp", $this->_tarname);
> return false;
> }
> @@ -1460,8 +1627,10 @@
> $v_buffered_lines[] = @bzread($v_temp_tar, 512);
>
> // ----- Read the following blocks but not the last one
> - while (strlen($v_buffered_lines[] = @bzread($v_temp_tar, 512)) > 0) {
> - $v_binary_data = pack("a512", array_shift($v_buffered_lines));
> + while (strlen($v_buffered_lines[]
> + = @bzread($v_temp_tar, 512)) > 0) {
> + $v_binary_data = pack("a512",
> + array_shift($v_buffered_lines));
> $this->_writeBlock($v_binary_data);
> }
>
> @@ -1469,11 +1638,13 @@
> }
>
> if (!@unlink($this->_tarname.".tmp")) {
> - $this->_error('Error while deleting temporary file
\''.$this->_tarname.'.tmp\'');
> + $this->_error('Error while deleting temporary file \''
> + .$this->_tarname.'.tmp\'');
> }
>
> } else {
> - // ----- For not compressed tar, just add files before the last 512 bytes block
> + // ----- For not compressed tar, just add files before the last
> + // 512 bytes block
> if (!$this->_openReadWrite())
> return false;
>
> @@ -1536,8 +1707,8 @@
> // {{{ _pathReduction()
>
> /**
> - * Compress path by changing for example "/dir/foo/../bar" to
"/dir/bar", and
> - * remove double slashes.
> + * Compress path by changing for example "/dir/foo/../bar" to
"/dir/bar",
> + * rand emove double slashes.
> *
> * @param string $p_dir path to reduce
> *
> @@ -1566,11 +1737,14 @@
> // ----- Ignore it and ignore the $i-1
> $i--;
> }
> - else if (($v_list[$i] == '') && ($i!=(sizeof($v_list)-1))
&& ($i!=0)) {
> + else if ( ($v_list[$i] == '')
> + && ($i!=(sizeof($v_list)-1))
> + && ($i!=0)) {
> // ----- Ignore only the double '//' in path,
> // but not the first and last /
> } else {
> - $v_result =
$v_list[$i].($i!=(sizeof($v_list)-1)?'/'.$v_result:'');
> + $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?'/'
> + .$v_result:'');
> }
> }
> }
> @@ -1583,9 +1757,10 @@
> // {{{ _translateWinPath()
> function _translateWinPath($p_path, $p_remove_disk_letter=true)
> {
> - if (OS_WINDOWS) {
> + if (defined('OS_WINDOWS') && OS_WINDOWS) {
> // ----- Look for potential disk letter
> - if (($p_remove_disk_letter) && (($v_position = strpos($p_path,
':')) != false)) {
> + if ( ($p_remove_disk_letter)
> + && (($v_position = strpos($p_path, ':')) != false)) {
> $p_path = substr($p_path, $v_position+1);
> }
> // ----- Change potential windows directory separator