Changeset 21495 for branches/version-2_12-dev/data/module
- Timestamp:
- 2012/02/13 15:51:23 (12 years ago)
- 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 31 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 32 * 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 41 40 */ 42 41 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", '')); 42 require_once 'PEAR.php'; 43 44 define('ARCHIVE_TAR_ATT_SEPARATOR', 90001); 45 define('ARCHIVE_TAR_END_BLOCK', pack("a512", '')); 52 46 53 47 /** 54 48 * Creates a (compressed) Tar archive 55 49 * 56 * @ author Vincent Blavet <vincent@phpconcept.net>57 * @ version $Revision: 295988 $58 * @license 59 * @ package Archive_Tar50 * @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 $ 60 54 */ 61 55 class Archive_Tar extends PEAR … … 95 89 */ 96 90 var $_ignore_regexp=''; 91 92 /** 93 * @var object PEAR_Error object 94 */ 95 var $error_object=null; 97 96 98 97 // {{{ constructor … … 104 103 * gzip or bz2 compressed TAR file. 105 104 * 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 * 111 111 * @access public 112 112 */ … … 125 125 $this->_compress = true; 126 126 $this->_compress_type = 'gz'; 127 // No sure it's enought for a magic code ....127 // No sure it's enought for a magic code .... 128 128 } elseif ($data == "BZ") { 129 129 $this->_compress = true; … … 202 202 * See also createModify() method for more details. 203 203 * 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() 209 210 * @access public 210 211 */ … … 224 225 * See also createModify() method for more details. 225 226 * 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() 231 233 * @access public 232 234 */ … … 238 240 239 241 // {{{ 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); 243 245 } 244 246 // }}} … … 284 286 * See also addModify() method for file adding properties. 285 287 * 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. 296 299 * @access public 297 300 * @see addModify() … … 356 359 * error text is send to PEAR error. 357 360 * 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. 369 373 * @access public 370 374 */ … … 375 379 if (!$this->_isArchive()) 376 380 $v_result = $this->createModify($p_filelist, $p_add_dir, 377 381 $p_remove_dir); 378 382 else { 379 383 if (is_array($p_filelist)) … … 399 403 * is created. 400 404 * 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. 407 412 * @access public 408 413 */ … … 457 462 * need to be manually cleaned. 458 463 * 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. 465 472 * @access public 466 * @see extractList()473 * @see extractList() 467 474 */ 468 function extractModify($p_path, $p_remove_path )475 function extractModify($p_path, $p_remove_path, $p_preserve=false) 469 476 { 470 477 $v_result = true; … … 473 480 if ($v_result = $this->_openRead()) { 474 481 $v_result = $this->_extractList($p_path, $v_list_detail, 475 "complete", 0, $p_remove_path);482 "complete", 0, $p_remove_path, $p_preserve); 476 483 $this->_close(); 477 484 } … … 485 492 * This method extract from the archive one file identified by $p_filename. 486 493 * 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. 489 498 * @access public 490 499 */ … … 495 504 $this->_close(); 496 505 } else { 497 $v_result = NULL;506 $v_result = null; 498 507 } 499 508 … … 509 518 * If indicated the $p_remove_path can be used in the same way as it is 510 519 * 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. 520 532 * @access public 521 * @see extractModify()533 * @see extractModify() 522 534 */ 523 function extractList($p_filelist, $p_path='', $p_remove_path='' )535 function extractList($p_filelist, $p_path='', $p_remove_path='', $p_preserve=false) 524 536 { 525 537 $v_result = true; … … 537 549 if ($v_result = $this->_openRead()) { 538 550 $v_result = $this->_extractList($p_path, $v_list_detail, "partial", 539 $v_list, $p_remove_path);551 $v_list, $p_remove_path, $p_preserve); 540 552 $this->_close(); 541 553 } … … 550 562 * list of parameters, in the format attribute code + attribute values : 551 563 * $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. 554 568 * @access public 555 569 */ … … 604 618 * at import, for example: 605 619 * $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 * 607 623 * @access public 608 624 */ … … 618 634 * matching the filenames in the array list at import, for example: 619 635 * $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 * 621 639 * @access public 622 640 */ … … 632 650 function _error($p_message) 633 651 { 634 // ----- To be completed 635 $this->raiseError($p_message); 652 $this->error_object = &$this->raiseError($p_message); 636 653 } 637 654 // }}} … … 640 657 function _warning($p_message) 641 658 { 642 // ----- To be completed 643 $this->raiseError($p_message); 659 $this->error_object = &$this->raiseError($p_message); 644 660 } 645 661 // }}} 646 662 647 663 // {{{ _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) { 651 667 $p_filename = $this->_tarname; 652 668 } … … 928 944 } 929 945 930 if (!file_exists($v_filename) ) {946 if (!file_exists($v_filename) && !is_link($v_filename)) { 931 947 $this->_warning("File '$v_filename' does not exist"); 932 948 continue; … … 1095 1111 1096 1112 $v_version = ' '; 1097 1113 1098 1114 if (function_exists('posix_getpwuid')) 1099 1115 { 1100 1116 $userinfo = posix_getpwuid($v_info[4]); 1101 1117 $groupinfo = posix_getgrgid($v_info[5]); 1102 1118 1103 1119 $v_uname = $userinfo['name']; 1104 1120 $v_gname = $groupinfo['name']; … … 1184 1200 $userinfo = posix_getpwuid($p_uid); 1185 1201 $groupinfo = posix_getgrgid($p_gid); 1186 1202 1187 1203 $v_uname = $userinfo['name']; 1188 1204 $v_gname = $groupinfo['name']; … … 1193 1209 $v_gname = ''; 1194 1210 } 1195 1211 1196 1212 $v_devmajor = ''; 1197 1213 … … 1328 1344 $v_checksum+=ord(substr($v_binary_data,$i,1)); 1329 1345 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 } 1334 1354 1335 1355 // ----- Extract the checksum … … 1383 1403 * 1384 1404 * @param string $file 1405 * 1385 1406 * @return bool 1386 1407 * @access private … … 1433 1454 /** 1434 1455 * 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. 1438 1461 * @access private 1439 1462 */ … … 1445 1468 { 1446 1469 if (!$this->_readHeader($v_binary_data, $v_header)) 1447 return NULL;1470 return null; 1448 1471 1449 1472 if ($v_header['filename'] == '') … … 1453 1476 if ($v_header['typeflag'] == 'L') { 1454 1477 if (!$this->_readLongHeader($v_header)) 1455 return NULL;1478 return null; 1456 1479 } 1457 1480 … … 1460 1483 $this->_error('Unable to extract in string a directory ' 1461 1484 .'entry {'.$v_header['filename'].'}'); 1462 return NULL;1485 return null; 1463 1486 } else { 1464 1487 $n = floor($v_header['size']/512); … … 1478 1501 } 1479 1502 1480 return NULL;1503 return null; 1481 1504 } 1482 1505 // }}} … … 1484 1507 // {{{ _extractList() 1485 1508 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) 1487 1510 { 1488 1511 $v_result=true; … … 1505 1528 switch ($p_mode) { 1506 1529 case "complete" : 1507 $v_extract_all = TRUE;1508 $v_listing = FALSE;1530 $v_extract_all = true; 1531 $v_listing = false; 1509 1532 break; 1510 1533 case "partial" : 1511 $v_extract_all = FALSE;1512 $v_listing = FALSE;1534 $v_extract_all = false; 1535 $v_listing = false; 1513 1536 break; 1514 1537 case "list" : 1515 $v_extract_all = FALSE;1516 $v_listing = TRUE;1538 $v_extract_all = false; 1539 $v_listing = true; 1517 1540 break; 1518 1541 default : … … 1552 1575 && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) 1553 1576 == $p_file_list[$i])) { 1554 $v_extract_file = TRUE;1577 $v_extract_file = true; 1555 1578 break; 1556 1579 } … … 1559 1582 // ----- It is a file, so compare the file names 1560 1583 elseif ($p_file_list[$i] == $v_header['filename']) { 1561 $v_extract_file = TRUE;1584 $v_extract_file = true; 1562 1585 break; 1563 1586 } 1564 1587 } 1565 1588 } else { 1566 $v_extract_file = TRUE;1589 $v_extract_file = true; 1567 1590 } 1568 1591 … … 1651 1674 1652 1675 @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 } 1653 1681 1654 1682 // ----- Change the file mode, mtime … … 1663 1691 // ----- Check the file size 1664 1692 clearstatcache(); 1665 if ( filesize($v_header['filename']) != $v_header['size']) {1693 if (!is_file($v_header['filename'])) { 1666 1694 $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.'); 1671 1706 return false; 1672 1707 } … … 1817 1852 * @param string $p_dir directory to check 1818 1853 * 1819 * @return bool TRUEif the directory exists or was created1854 * @return bool true if the directory exists or was created 1820 1855 */ 1821 1856 function _dirCheck($p_dir)
Note: See TracChangeset
for help on using the changeset viewer.