Ignore:
Timestamp:
2012/02/13 15:51:23 (12 years ago)
Author:
Seasoft
Message:

#1639 (PEAR::Archive_Tar 配置が誤っている)
#1640 (PEAR::Archive_Tar アップデート)

  • 1.3.8
Location:
branches/version-2_12-dev/data/module/Archive
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/module/Archive/Tar.php

    r21018 r21495  
    3131 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    3232 * 
    33  * 
    34  * @category    File_Formats 
    35  * @package     Archive_Tar 
    36  * @author      Vincent Blavet <vincent@phpconcept.net> 
    37  * @copyright   1997-2008 The Authors 
    38  * @license     http://www.opensource.org/licenses/bsd-license.php New BSD License 
    39  * @version     CVS: $Id$ 
    40  * @link        http://pear.php.net/package/Archive_Tar 
     33 * @category  File_Formats 
     34 * @package   Archive_Tar 
     35 * @author    Vincent Blavet <vincent@phpconcept.net> 
     36 * @copyright 1997-2010 The Authors 
     37 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License 
     38 * @version   CVS: $Id$ 
     39 * @link      http://pear.php.net/package/Archive_Tar 
    4140 */ 
    4241 
    43 if(!defined('TAR_PHP_DIR')) { 
    44     $TAR_PHP_DIR = realpath(dirname( __FILE__)); 
    45     define("TAR_PHP_DIR", $TAR_PHP_DIR); 
    46 } 
    47  
    48 require_once TAR_PHP_DIR . '/PEAR.php'; 
    49  
    50 define ('ARCHIVE_TAR_ATT_SEPARATOR', 90001); 
    51 define ('ARCHIVE_TAR_END_BLOCK', pack("a512", '')); 
     42require_once 'PEAR.php'; 
     43 
     44define('ARCHIVE_TAR_ATT_SEPARATOR', 90001); 
     45define('ARCHIVE_TAR_END_BLOCK', pack("a512", '')); 
    5246 
    5347/** 
    5448* Creates a (compressed) Tar archive 
    5549* 
    56 * @author   Vincent Blavet <vincent@phpconcept.net> 
    57 * @version  $Revision: 295988 $ 
    58 * @license  http://www.opensource.org/licenses/bsd-license.php New BSD License 
    59 * @package  Archive_Tar 
     50* @package Archive_Tar 
     51* @author  Vincent Blavet <vincent@phpconcept.net> 
     52* @license http://www.opensource.org/licenses/bsd-license.php New BSD License 
     53* @version $Revision: 314430 $ 
    6054*/ 
    6155class Archive_Tar extends PEAR 
     
    9589    */ 
    9690    var $_ignore_regexp=''; 
     91 
     92    /** 
     93     * @var object PEAR_Error object 
     94     */ 
     95    var $error_object=null;  
    9796 
    9897    // {{{ constructor 
     
    104103    * gzip or bz2 compressed TAR file. 
    105104    * 
    106     * @param    string  $p_tarname  The name of the tar archive to create 
    107     * @param    string  $p_compress can be null, 'gz' or 'bz2'. This 
    108     *                   parameter indicates if gzip or bz2 compression 
    109     *                   is required.  For compatibility reason the 
    110     *                   boolean value 'true' means 'gz'. 
     105    * @param string $p_tarname  The name of the tar archive to create 
     106    * @param string $p_compress can be null, 'gz' or 'bz2'. This 
     107    *               parameter indicates if gzip or bz2 compression 
     108    *               is required.  For compatibility reason the 
     109    *               boolean value 'true' means 'gz'. 
     110    * 
    111111    * @access public 
    112112    */ 
     
    125125                        $this->_compress = true; 
    126126                        $this->_compress_type = 'gz'; 
    127                     // No sure it's enought for a magic code .... 
     127                        // No sure it's enought for a magic code .... 
    128128                    } elseif ($data == "BZ") { 
    129129                        $this->_compress = true; 
     
    202202    * See also createModify() method for more details. 
    203203    * 
    204     * @param array  $p_filelist An array of filenames and directory names, or a 
    205     *                           single string with names separated by a single 
    206     *                           blank space. 
    207     * @return                   true on success, false on error. 
    208     * @see createModify() 
     204    * @param array $p_filelist An array of filenames and directory names, or a 
     205    *              single string with names separated by a single 
     206    *              blank space. 
     207    * 
     208    * @return true on success, false on error. 
     209    * @see    createModify() 
    209210    * @access public 
    210211    */ 
     
    224225    * See also createModify() method for more details. 
    225226    * 
    226     * @param array  $p_filelist An array of filenames and directory names, or a 
    227     *                           single string with names separated by a single 
    228     *                           blank space. 
    229     * @return                   true on success, false on error. 
    230     * @see createModify() 
     227    * @param array $p_filelist An array of filenames and directory names, or a 
     228    *              single string with names separated by a single 
     229    *              blank space. 
     230    * 
     231    * @return true on success, false on error. 
     232    * @see    createModify() 
    231233    * @access public 
    232234    */ 
     
    238240 
    239241    // {{{ extract() 
    240     function extract($p_path='') 
    241     { 
    242         return $this->extractModify($p_path, ''); 
     242    function extract($p_path='', $p_preserve=false) 
     243    { 
     244        return $this->extractModify($p_path, '', $p_preserve); 
    243245    } 
    244246    // }}} 
     
    284286    * See also addModify() method for file adding properties. 
    285287    * 
    286     * @param array  $p_filelist     An array of filenames and directory names, 
    287     *                               or a single string with names separated by 
    288     *                               a single blank space. 
    289     * @param string $p_add_dir      A string which contains a path to be added 
    290     *                               to the memorized path of each element in 
    291     *                               the list. 
    292     * @param string $p_remove_dir   A string which contains a path to be 
    293     *                               removed from the memorized path of each 
    294     *                               element in the list, when relevant. 
    295     * @return boolean               true on success, false on error. 
     288    * @param array  $p_filelist   An array of filenames and directory names, 
     289    *                             or a single string with names separated by 
     290    *                             a single blank space. 
     291    * @param string $p_add_dir    A string which contains a path to be added 
     292    *                             to the memorized path of each element in 
     293    *                             the list. 
     294    * @param string $p_remove_dir A string which contains a path to be 
     295    *                             removed from the memorized path of each 
     296    *                             element in the list, when relevant. 
     297    * 
     298    * @return boolean true on success, false on error. 
    296299    * @access public 
    297300    * @see addModify() 
     
    356359    * error text is send to PEAR error. 
    357360    * 
    358     * @param array      $p_filelist     An array of filenames and directory 
    359     *                                   names, or a single string with names 
    360     *                                   separated by a single blank space. 
    361     * @param string     $p_add_dir      A string which contains a path to be 
    362     *                                   added to the memorized path of each 
    363     *                                   element in the list. 
    364     * @param string     $p_remove_dir   A string which contains a path to be 
    365     *                                   removed from the memorized path of 
    366     *                                   each element in the list, when 
    367     *                                   relevant. 
    368     * @return                           true on success, false on error. 
     361    * @param array  $p_filelist   An array of filenames and directory 
     362    *                             names, or a single string with names 
     363    *                             separated by a single blank space. 
     364    * @param string $p_add_dir    A string which contains a path to be 
     365    *                             added to the memorized path of each 
     366    *                             element in the list. 
     367    * @param string $p_remove_dir A string which contains a path to be 
     368    *                             removed from the memorized path of 
     369    *                             each element in the list, when 
     370    *                             relevant. 
     371    * 
     372    * @return true on success, false on error. 
    369373    * @access public 
    370374    */ 
     
    375379        if (!$this->_isArchive()) 
    376380            $v_result = $this->createModify($p_filelist, $p_add_dir, 
    377                                             $p_remove_dir); 
     381                                            $p_remove_dir); 
    378382        else { 
    379383            if (is_array($p_filelist)) 
     
    399403    * is created. 
    400404    * 
    401     * @param string     $p_filename     A string which contains the full 
    402     *                                   filename path that will be associated 
    403     *                                   with the string. 
    404     * @param string     $p_string       The content of the file added in 
    405     *                                   the archive. 
    406     * @return                           true on success, false on error. 
     405    * @param string $p_filename A string which contains the full 
     406    *                           filename path that will be associated 
     407    *                           with the string. 
     408    * @param string $p_string   The content of the file added in 
     409    *                           the archive. 
     410    * 
     411    * @return true on success, false on error. 
    407412    * @access public 
    408413    */ 
     
    457462    * need to be manually cleaned. 
    458463    * 
    459     * @param string $p_path         The path of the directory where the 
    460     *                               files/dir need to by extracted. 
    461     * @param string $p_remove_path  Part of the memorized path that can be 
    462     *                               removed if present at the beginning of 
    463     *                               the file/dir path. 
    464     * @return boolean               true on success, false on error. 
     464    * @param string  $p_path        The path of the directory where the 
     465    *                               files/dir need to by extracted. 
     466    * @param string  $p_remove_path Part of the memorized path that can be 
     467    *                               removed if present at the beginning of 
     468    *                               the file/dir path. 
     469    * @param boolean $p_preserve    Preserve user/group ownership of files 
     470    * 
     471    * @return boolean true on success, false on error. 
    465472    * @access public 
    466     * @see extractList() 
     473    * @see    extractList() 
    467474    */ 
    468     function extractModify($p_path, $p_remove_path) 
     475    function extractModify($p_path, $p_remove_path, $p_preserve=false) 
    469476    { 
    470477        $v_result = true; 
     
    473480        if ($v_result = $this->_openRead()) { 
    474481            $v_result = $this->_extractList($p_path, $v_list_detail, 
    475                                             "complete", 0, $p_remove_path); 
     482                "complete", 0, $p_remove_path, $p_preserve); 
    476483            $this->_close(); 
    477484        } 
     
    485492    * This method extract from the archive one file identified by $p_filename. 
    486493    * The return value is a string with the file content, or NULL on error. 
    487     * @param string $p_filename     The path of the file to extract in a string. 
    488     * @return                       a string with the file content or NULL. 
     494    * 
     495    * @param string $p_filename The path of the file to extract in a string. 
     496    * 
     497    * @return a string with the file content or NULL. 
    489498    * @access public 
    490499    */ 
     
    495504            $this->_close(); 
    496505        } else { 
    497             $v_result = NULL; 
     506            $v_result = null; 
    498507        } 
    499508 
     
    509518    * If indicated the $p_remove_path can be used in the same way as it is 
    510519    * used in extractModify() method. 
    511     * @param array  $p_filelist     An array of filenames and directory names, 
    512     *                               or a single string with names separated 
    513     *                               by a single blank space. 
    514     * @param string $p_path         The path of the directory where the 
    515     *                               files/dir need to by extracted. 
    516     * @param string $p_remove_path  Part of the memorized path that can be 
    517     *                               removed if present at the beginning of 
    518     *                               the file/dir path. 
    519     * @return                       true on success, false on error. 
     520    * 
     521    * @param array   $p_filelist    An array of filenames and directory names, 
     522    *                               or a single string with names separated 
     523    *                               by a single blank space. 
     524    * @param string  $p_path        The path of the directory where the 
     525    *                               files/dir need to by extracted. 
     526    * @param string  $p_remove_path Part of the memorized path that can be 
     527    *                               removed if present at the beginning of 
     528    *                               the file/dir path. 
     529    * @param boolean $p_preserve    Preserve user/group ownership of files 
     530    * 
     531    * @return true on success, false on error. 
    520532    * @access public 
    521     * @see extractModify() 
     533    * @see    extractModify() 
    522534    */ 
    523     function extractList($p_filelist, $p_path='', $p_remove_path='') 
     535    function extractList($p_filelist, $p_path='', $p_remove_path='', $p_preserve=false) 
    524536    { 
    525537        $v_result = true; 
     
    537549        if ($v_result = $this->_openRead()) { 
    538550            $v_result = $this->_extractList($p_path, $v_list_detail, "partial", 
    539                                             $v_list, $p_remove_path); 
     551                $v_list, $p_remove_path, $p_preserve); 
    540552            $this->_close(); 
    541553        } 
     
    550562    * list of parameters, in the format attribute code + attribute values : 
    551563    * $arch->setAttribute(ARCHIVE_TAR_ATT_SEPARATOR, ','); 
    552     * @param mixed $argv            variable list of attributes and values 
    553     * @return                       true on success, false on error. 
     564    * 
     565    * @param mixed $argv variable list of attributes and values 
     566    * 
     567    * @return true on success, false on error. 
    554568    * @access public 
    555569    */ 
     
    604618    * at import, for example: 
    605619    * $arch->setIgnoreRegexp("#CVS|\.svn#"); 
    606     * @param string $regexp         regular expression defining which files or directories to ignore 
     620    * 
     621    * @param string $regexp regular expression defining which files or directories to ignore 
     622    * 
    607623    * @access public 
    608624    */ 
     
    618634    * matching the filenames in the array list at import, for example: 
    619635    * $arch->setIgnoreList(array('CVS', '.svn', 'bin/tool')); 
    620     * @param array $list         a list of file or directory names to ignore 
     636    * 
     637    * @param array $list a list of file or directory names to ignore 
     638    * 
    621639    * @access public 
    622640    */ 
     
    632650    function _error($p_message) 
    633651    { 
    634         // ----- To be completed 
    635         $this->raiseError($p_message); 
     652        $this->error_object = &$this->raiseError($p_message);  
    636653    } 
    637654    // }}} 
     
    640657    function _warning($p_message) 
    641658    { 
    642         // ----- To be completed 
    643         $this->raiseError($p_message); 
     659        $this->error_object = &$this->raiseError($p_message);  
    644660    } 
    645661    // }}} 
    646662 
    647663    // {{{ _isArchive() 
    648     function _isArchive($p_filename=NULL) 
    649     { 
    650         if ($p_filename == NULL) { 
     664    function _isArchive($p_filename=null) 
     665    { 
     666        if ($p_filename == null) { 
    651667            $p_filename = $this->_tarname; 
    652668        } 
     
    928944        } 
    929945 
    930         if (!file_exists($v_filename)) { 
     946        if (!file_exists($v_filename) && !is_link($v_filename)) { 
    931947            $this->_warning("File '$v_filename' does not exist"); 
    932948            continue; 
     
    10951111 
    10961112        $v_version = ' '; 
    1097  
     1113         
    10981114        if (function_exists('posix_getpwuid')) 
    10991115        { 
    11001116          $userinfo = posix_getpwuid($v_info[4]); 
    11011117          $groupinfo = posix_getgrgid($v_info[5]); 
    1102  
     1118           
    11031119          $v_uname = $userinfo['name']; 
    11041120          $v_gname = $groupinfo['name']; 
     
    11841200          $userinfo = posix_getpwuid($p_uid); 
    11851201          $groupinfo = posix_getgrgid($p_gid); 
    1186  
     1202           
    11871203          $v_uname = $userinfo['name']; 
    11881204          $v_gname = $groupinfo['name']; 
     
    11931209          $v_gname = ''; 
    11941210        } 
    1195  
     1211         
    11961212        $v_devmajor = ''; 
    11971213 
     
    13281344           $v_checksum+=ord(substr($v_binary_data,$i,1)); 
    13291345 
    1330         $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" 
    1331                          ."a8checksum/a1typeflag/a100link/a6magic/a2version/" 
    1332                          ."a32uname/a32gname/a8devmajor/a8devminor", 
    1333                          $v_binary_data); 
     1346        $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" . 
     1347                         "a8checksum/a1typeflag/a100link/a6magic/a2version/" . 
     1348                         "a32uname/a32gname/a8devmajor/a8devminor/a131prefix", 
     1349                         $v_binary_data); 
     1350                          
     1351        if (strlen($v_data["prefix"]) > 0) { 
     1352            $v_data["filename"] = "$v_data[prefix]/$v_data[filename]"; 
     1353        } 
    13341354 
    13351355        // ----- Extract the checksum 
     
    13831403     * 
    13841404     * @param string $file 
     1405     * 
    13851406     * @return bool 
    13861407     * @access private 
     
    14331454    /** 
    14341455    * This method extract from the archive one file identified by $p_filename. 
    1435     * The return value is a string with the file content, or NULL on error. 
    1436     * @param string $p_filename     The path of the file to extract in a string. 
    1437     * @return                       a string with the file content or NULL. 
     1456    * The return value is a string with the file content, or null on error. 
     1457    * 
     1458    * @param string $p_filename The path of the file to extract in a string. 
     1459    * 
     1460    * @return a string with the file content or null. 
    14381461    * @access private 
    14391462    */ 
     
    14451468        { 
    14461469          if (!$this->_readHeader($v_binary_data, $v_header)) 
    1447             return NULL; 
     1470            return null; 
    14481471 
    14491472          if ($v_header['filename'] == '') 
     
    14531476          if ($v_header['typeflag'] == 'L') { 
    14541477            if (!$this->_readLongHeader($v_header)) 
    1455               return NULL; 
     1478              return null; 
    14561479          } 
    14571480 
     
    14601483                  $this->_error('Unable to extract in string a directory ' 
    14611484                                .'entry {'.$v_header['filename'].'}'); 
    1462                   return NULL; 
     1485                  return null; 
    14631486              } else { 
    14641487                  $n = floor($v_header['size']/512); 
     
    14781501        } 
    14791502 
    1480         return NULL; 
     1503        return null; 
    14811504    } 
    14821505    // }}} 
     
    14841507    // {{{ _extractList() 
    14851508    function _extractList($p_path, &$p_list_detail, $p_mode, 
    1486                           $p_file_list, $p_remove_path) 
     1509                          $p_file_list, $p_remove_path, $p_preserve=false) 
    14871510    { 
    14881511    $v_result=true; 
     
    15051528    switch ($p_mode) { 
    15061529      case "complete" : 
    1507         $v_extract_all = TRUE; 
    1508         $v_listing = FALSE; 
     1530        $v_extract_all = true; 
     1531        $v_listing = false; 
    15091532      break; 
    15101533      case "partial" : 
    1511           $v_extract_all = FALSE; 
    1512           $v_listing = FALSE; 
     1534          $v_extract_all = false; 
     1535          $v_listing = false; 
    15131536      break; 
    15141537      case "list" : 
    1515           $v_extract_all = FALSE; 
    1516           $v_listing = TRUE; 
     1538          $v_extract_all = false; 
     1539          $v_listing = true; 
    15171540      break; 
    15181541      default : 
     
    15521575                && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) 
    15531576                    == $p_file_list[$i])) { 
    1554               $v_extract_file = TRUE; 
     1577              $v_extract_file = true; 
    15551578              break; 
    15561579            } 
     
    15591582          // ----- It is a file, so compare the file names 
    15601583          elseif ($p_file_list[$i] == $v_header['filename']) { 
    1561             $v_extract_file = TRUE; 
     1584            $v_extract_file = true; 
    15621585            break; 
    15631586          } 
    15641587        } 
    15651588      } else { 
    1566         $v_extract_file = TRUE; 
     1589        $v_extract_file = true; 
    15671590      } 
    15681591 
     
    16511674 
    16521675            @fclose($v_dest_file); 
     1676             
     1677            if ($p_preserve) { 
     1678                @chown($v_header['filename'], $v_header['uid']); 
     1679                @chgrp($v_header['filename'], $v_header['gid']); 
     1680            } 
    16531681 
    16541682            // ----- Change the file mode, mtime 
     
    16631691          // ----- Check the file size 
    16641692          clearstatcache(); 
    1665           if (filesize($v_header['filename']) != $v_header['size']) { 
     1693          if (!is_file($v_header['filename'])) { 
    16661694              $this->_error('Extracted file '.$v_header['filename'] 
    1667                             .' does not have the correct file size \'' 
    1668                             .filesize($v_header['filename']) 
    1669                             .'\' ('.$v_header['size'] 
    1670                             .' expected). Archive may be corrupted.'); 
     1695                            .'does not exist. Archive may be corrupted.'); 
     1696              return false; 
     1697          } 
     1698           
     1699          $filesize = filesize($v_header['filename']); 
     1700          if ($filesize != $v_header['size']) { 
     1701              $this->_error('Extracted file '.$v_header['filename'] 
     1702                            .' does not have the correct file size \'' 
     1703                            .$filesize 
     1704                            .'\' ('.$v_header['size'] 
     1705                            .' expected). Archive may be corrupted.'); 
    16711706              return false; 
    16721707          } 
     
    18171852     * @param string $p_dir directory to check 
    18181853     * 
    1819      * @return bool TRUE if the directory exists or was created 
     1854     * @return bool true if the directory exists or was created 
    18201855     */ 
    18211856    function _dirCheck($p_dir) 
Note: See TracChangeset for help on using the changeset viewer.