Changeset 22964
- Timestamp:
- 2013/07/17 11:56:08 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/module/Archive/Tar.php
r21495 r22964 51 51 * @author Vincent Blavet <vincent@phpconcept.net> 52 52 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License 53 * @version $Revision : 314430$53 * @version $Revision$ 54 54 */ 55 55 class Archive_Tar extends PEAR … … 408 408 * @param string $p_string The content of the file added in 409 409 * the archive. 410 * @param int $p_datetime A custom date/time (unix timestamp) 411 * for the file (optional). 410 412 * 411 413 * @return true on success, false on error. 412 414 * @access public 413 415 */ 414 function addString($p_filename, $p_string )416 function addString($p_filename, $p_string, $p_datetime = false) 415 417 { 416 418 $v_result = true; … … 427 429 428 430 // 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); 430 432 431 433 $this->_writeFooter(); … … 675 677 function _openWrite() 676 678 { 677 if ($this->_compress_type == 'gz' )679 if ($this->_compress_type == 'gz' && function_exists('gzopen')) 678 680 $this->_file = @gzopen($this->_tarname, "wb9"); 679 else if ($this->_compress_type == 'bz2' )681 else if ($this->_compress_type == 'bz2' && function_exists('bzopen')) 680 682 $this->_file = @bzopen($this->_tarname, "w"); 681 683 else if ($this->_compress_type == 'none') 682 684 $this->_file = @fopen($this->_tarname, "wb"); 683 else 685 else { 684 686 $this->_error('Unknown or missing compression type (' 685 687 .$this->_compress_type.')'); 688 return false; 689 } 686 690 687 691 if ($this->_file == 0) { … … 728 732 $v_filename = $this->_tarname; 729 733 730 if ($this->_compress_type == 'gz' )734 if ($this->_compress_type == 'gz' && function_exists('gzopen')) 731 735 $this->_file = @gzopen($v_filename, "rb"); 732 else if ($this->_compress_type == 'bz2' )736 else if ($this->_compress_type == 'bz2' && function_exists('bzopen')) 733 737 $this->_file = @bzopen($v_filename, "r"); 734 738 else if ($this->_compress_type == 'none') 735 739 $this->_file = @fopen($v_filename, "rb"); 736 else 740 else { 737 741 $this->_error('Unknown or missing compression type (' 738 742 .$this->_compress_type.')'); 743 return false; 744 } 739 745 740 746 if ($this->_file == 0) { … … 758 764 } else if ($this->_compress_type == 'none') 759 765 $this->_file = @fopen($this->_tarname, "r+b"); 760 else 766 else { 761 767 $this->_error('Unknown or missing compression type (' 762 768 .$this->_compress_type.')'); 769 return false; 770 } 763 771 764 772 if ($this->_file == 0) { … … 1045 1053 1046 1054 // {{{ _addString() 1047 function _addString($p_filename, $p_string )1055 function _addString($p_filename, $p_string, $p_datetime = false) 1048 1056 { 1049 1057 if (!$this->_file) { … … 1059 1067 // ----- Calculate the stored filename 1060 1068 $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 } 1061 1074 1062 1075 if (!$this->_writeHeaderBlock($p_filename, strlen($p_string), 1063 time(), 384, "", 0, 0))1076 $p_datetime, 384, "", 0, 0)) 1064 1077 return false; 1065 1078 … … 1344 1357 $v_checksum+=ord(substr($v_binary_data,$i,1)); 1345 1358 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 1351 1370 if (strlen($v_data["prefix"]) > 0) { 1352 1371 $v_data["filename"] = "$v_data[prefix]/$v_data[filename]"; … … 1594 1613 { 1595 1614 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)) { 1598 1617 $v_header['filename'] = substr($v_header['filename'], 1599 1618 $p_remove_path_size); 1619 if( $v_header['filename'] == '' ){ 1620 continue; 1621 } 1622 } 1600 1623 if (($p_path != './') && ($p_path != '/')) { 1601 1624 while (substr($p_path, -1) == '/') … … 1774 1797 1775 1798 if ($this->_compress_type == 'gz') { 1799 $end_blocks = 0; 1800 1776 1801 while (!@gzeof($v_temp_tar)) { 1777 1802 $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++; 1779 1805 // do not copy end blocks, we will re-make them 1780 1806 // after appending 1781 1807 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; 1782 1813 } 1783 1814 $v_binary_data = pack("a512", $v_buffer); … … 1788 1819 } 1789 1820 elseif ($this->_compress_type == 'bz2') { 1821 $end_blocks = 0; 1822 1790 1823 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 1792 1828 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; 1793 1834 } 1794 1835 $v_binary_data = pack("a512", $v_buffer); … … 1921 1962 } 1922 1963 } 1923 $v_result = strtr($v_result, '\\', '/'); 1964 1965 if (defined('OS_WINDOWS') && OS_WINDOWS) { 1966 $v_result = strtr($v_result, '\\', '/'); 1967 } 1968 1924 1969 return $v_result; 1925 1970 }
Note: See TracChangeset
for help on using the changeset viewer.