Changeset 22964


Ignore:
Timestamp:
2013/07/17 11:56:08 (11 years ago)
Author:
kimoto
Message:

#2275 PHP5.5対応
Archive_Tar を最新版に更新

File:
1 edited

Legend:

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

    r21495 r22964  
    5151* @author  Vincent Blavet <vincent@phpconcept.net> 
    5252* @license http://www.opensource.org/licenses/bsd-license.php New BSD License 
    53 * @version $Revision: 314430 $ 
     53* @version $Revision$ 
    5454*/ 
    5555class Archive_Tar extends PEAR 
     
    408408    * @param string $p_string   The content of the file added in 
    409409    *                           the archive. 
     410    * @param int    $p_datetime A custom date/time (unix timestamp) 
     411    *                           for the file (optional). 
    410412    * 
    411413    * @return true on success, false on error. 
    412414    * @access public 
    413415    */ 
    414     function addString($p_filename, $p_string) 
     416    function addString($p_filename, $p_string, $p_datetime = false) 
    415417    { 
    416418        $v_result = true; 
     
    427429 
    428430        // Need to check the get back to the temporary file ? .... 
    429         $v_result = $this->_addString($p_filename, $p_string); 
     431        $v_result = $this->_addString($p_filename, $p_string, $p_datetime); 
    430432 
    431433        $this->_writeFooter(); 
     
    675677    function _openWrite() 
    676678    { 
    677         if ($this->_compress_type == 'gz') 
     679        if ($this->_compress_type == 'gz' && function_exists('gzopen')) 
    678680            $this->_file = @gzopen($this->_tarname, "wb9"); 
    679         else if ($this->_compress_type == 'bz2') 
     681        else if ($this->_compress_type == 'bz2' && function_exists('bzopen')) 
    680682            $this->_file = @bzopen($this->_tarname, "w"); 
    681683        else if ($this->_compress_type == 'none') 
    682684            $this->_file = @fopen($this->_tarname, "wb"); 
    683         else 
     685        else { 
    684686            $this->_error('Unknown or missing compression type (' 
    685687                          .$this->_compress_type.')'); 
     688            return false; 
     689        } 
    686690 
    687691        if ($this->_file == 0) { 
     
    728732          $v_filename = $this->_tarname; 
    729733 
    730         if ($this->_compress_type == 'gz') 
     734        if ($this->_compress_type == 'gz' && function_exists('gzopen')) 
    731735            $this->_file = @gzopen($v_filename, "rb"); 
    732         else if ($this->_compress_type == 'bz2') 
     736        else if ($this->_compress_type == 'bz2' && function_exists('bzopen')) 
    733737            $this->_file = @bzopen($v_filename, "r"); 
    734738        else if ($this->_compress_type == 'none') 
    735739            $this->_file = @fopen($v_filename, "rb"); 
    736         else 
     740        else { 
    737741            $this->_error('Unknown or missing compression type (' 
    738742                          .$this->_compress_type.')'); 
     743            return false; 
     744        } 
    739745 
    740746        if ($this->_file == 0) { 
     
    758764        } else if ($this->_compress_type == 'none') 
    759765            $this->_file = @fopen($this->_tarname, "r+b"); 
    760         else 
     766        else { 
    761767            $this->_error('Unknown or missing compression type (' 
    762768                          .$this->_compress_type.')'); 
     769            return false; 
     770        } 
    763771 
    764772        if ($this->_file == 0) { 
     
    10451053 
    10461054    // {{{ _addString() 
    1047     function _addString($p_filename, $p_string) 
     1055    function _addString($p_filename, $p_string, $p_datetime = false) 
    10481056    { 
    10491057      if (!$this->_file) { 
     
    10591067      // ----- Calculate the stored filename 
    10601068      $p_filename = $this->_translateWinPath($p_filename, false);; 
     1069       
     1070      // ----- If datetime is not specified, set current time 
     1071      if ($p_datetime === false) { 
     1072          $p_datetime = time(); 
     1073      } 
    10611074 
    10621075      if (!$this->_writeHeaderBlock($p_filename, strlen($p_string), 
    1063                                       time(), 384, "", 0, 0)) 
     1076                                    $p_datetime, 384, "", 0, 0)) 
    10641077          return false; 
    10651078 
     
    13441357           $v_checksum+=ord(substr($v_binary_data,$i,1)); 
    13451358 
    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                           
     1359        if (version_compare(PHP_VERSION,"5.5.0-dev")<0) { 
     1360            $fmt = "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" . 
     1361                   "a8checksum/a1typeflag/a100link/a6magic/a2version/" . 
     1362                   "a32uname/a32gname/a8devmajor/a8devminor/a131prefix"; 
     1363        } else { 
     1364            $fmt = "Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/" . 
     1365                   "Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/" . 
     1366                   "Z32uname/Z32gname/Z8devmajor/Z8devminor/Z131prefix"; 
     1367        } 
     1368        $v_data = unpack($fmt, $v_binary_data); 
     1369 
    13511370        if (strlen($v_data["prefix"]) > 0) { 
    13521371            $v_data["filename"] = "$v_data[prefix]/$v_data[filename]"; 
     
    15941613      { 
    15951614        if (($p_remove_path != '') 
    1596             && (substr($v_header['filename'], 0, $p_remove_path_size) 
    1597                 == $p_remove_path)) 
     1615            && (substr($v_header['filename'].'/', 0, $p_remove_path_size) 
     1616                == $p_remove_path)) { 
    15981617          $v_header['filename'] = substr($v_header['filename'], 
    15991618                                         $p_remove_path_size); 
     1619          if( $v_header['filename'] == '' ){ 
     1620            continue; 
     1621          } 
     1622        } 
    16001623        if (($p_path != './') && ($p_path != '/')) { 
    16011624          while (substr($p_path, -1) == '/') 
     
    17741797 
    17751798            if ($this->_compress_type == 'gz') { 
     1799                $end_blocks = 0; 
     1800                 
    17761801                while (!@gzeof($v_temp_tar)) { 
    17771802                    $v_buffer = @gzread($v_temp_tar, 512); 
    1778                     if ($v_buffer == ARCHIVE_TAR_END_BLOCK) { 
     1803                    if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) { 
     1804                        $end_blocks++; 
    17791805                        // do not copy end blocks, we will re-make them 
    17801806                        // after appending 
    17811807                        continue; 
     1808                    } elseif ($end_blocks > 0) { 
     1809                        for ($i = 0; $i < $end_blocks; $i++) { 
     1810                            $this->_writeBlock(ARCHIVE_TAR_END_BLOCK); 
     1811                        } 
     1812                        $end_blocks = 0; 
    17821813                    } 
    17831814                    $v_binary_data = pack("a512", $v_buffer); 
     
    17881819            } 
    17891820            elseif ($this->_compress_type == 'bz2') { 
     1821                $end_blocks = 0; 
     1822                 
    17901823                while (strlen($v_buffer = @bzread($v_temp_tar, 512)) > 0) { 
    1791                     if ($v_buffer == ARCHIVE_TAR_END_BLOCK) { 
     1824                    if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) { 
     1825                        $end_blocks++; 
     1826                        // do not copy end blocks, we will re-make them 
     1827                        // after appending 
    17921828                        continue; 
     1829                    } elseif ($end_blocks > 0) { 
     1830                        for ($i = 0; $i < $end_blocks; $i++) { 
     1831                            $this->_writeBlock(ARCHIVE_TAR_END_BLOCK); 
     1832                        } 
     1833                        $end_blocks = 0; 
    17931834                    } 
    17941835                    $v_binary_data = pack("a512", $v_buffer); 
     
    19211962            } 
    19221963        } 
    1923         $v_result = strtr($v_result, '\\', '/'); 
     1964         
     1965        if (defined('OS_WINDOWS') && OS_WINDOWS) { 
     1966            $v_result = strtr($v_result, '\\', '/'); 
     1967        } 
     1968         
    19241969        return $v_result; 
    19251970    } 
Note: See TracChangeset for help on using the changeset viewer.