/usr/share/php/PEAR/Downloader/Package.php is in php-pear 5.3.10-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 | <?php
/**
* PEAR_Downloader_Package
*
* PHP versions 4 and 5
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id: Package.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
/**
* Error code when parameter initialization fails because no releases
* exist within preferred_state, but releases do exist
*/
define('PEAR_DOWNLOADER_PACKAGE_STATE', -1003);
/**
* Error code when parameter initialization fails because no releases
* exist that will work with the existing PHP version
*/
define('PEAR_DOWNLOADER_PACKAGE_PHPVERSION', -1004);
/**
* Coordinates download parameters and manages their dependencies
* prior to downloading them.
*
* Input can come from three sources:
*
* - local files (archives or package.xml)
* - remote files (downloadable urls)
* - abstract package names
*
* The first two elements are handled cleanly by PEAR_PackageFile, but the third requires
* accessing pearweb's xml-rpc interface to determine necessary dependencies, and the
* format returned of dependencies is slightly different from that used in package.xml.
*
* This class hides the differences between these elements, and makes automatic
* dependency resolution a piece of cake. It also manages conflicts when
* two classes depend on incompatible dependencies, or differing versions of the same
* package dependency. In addition, download will not be attempted if the php version is
* not supported, PEAR installer version is not supported, or non-PECL extensions are not
* installed.
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_Downloader_Package
{
/**
* @var PEAR_Downloader
*/
var $_downloader;
/**
* @var PEAR_Config
*/
var $_config;
/**
* @var PEAR_Registry
*/
var $_registry;
/**
* Used to implement packagingroot properly
* @var PEAR_Registry
*/
var $_installRegistry;
/**
* @var PEAR_PackageFile_v1|PEAR_PackageFile|v2
*/
var $_packagefile;
/**
* @var array
*/
var $_parsedname;
/**
* @var array
*/
var $_downloadURL;
/**
* @var array
*/
var $_downloadDeps = array();
/**
* @var boolean
*/
var $_valid = false;
/**
* @var boolean
*/
var $_analyzed = false;
/**
* if this or a parent package was invoked with Package-state, this is set to the
* state variable.
*
* This allows temporary reassignment of preferred_state for a parent package and all of
* its dependencies.
* @var string|false
*/
var $_explicitState = false;
/**
* If this package is invoked with Package#group, this variable will be true
*/
var $_explicitGroup = false;
/**
* Package type local|url
* @var string
*/
var $_type;
/**
* Contents of package.xml, if downloaded from a remote channel
* @var string|false
* @access private
*/
var $_rawpackagefile;
/**
* @var boolean
* @access private
*/
var $_validated = false;
/**
* @param PEAR_Downloader
*/
function PEAR_Downloader_Package(&$downloader)
{
$this->_downloader = &$downloader;
$this->_config = &$this->_downloader->config;
$this->_registry = &$this->_config->getRegistry();
$options = $downloader->getOptions();
if (isset($options['packagingroot'])) {
$this->_config->setInstallRoot($options['packagingroot']);
$this->_installRegistry = &$this->_config->getRegistry();
$this->_config->setInstallRoot(false);
} else {
$this->_installRegistry = &$this->_registry;
}
$this->_valid = $this->_analyzed = false;
}
/**
* Parse the input and determine whether this is a local file, a remote uri, or an
* abstract package name.
*
* This is the heart of the PEAR_Downloader_Package(), and is used in
* {@link PEAR_Downloader::download()}
* @param string
* @return bool|PEAR_Error
*/
function initialize($param)
{
$origErr = $this->_fromFile($param);
if ($this->_valid) {
return true;
}
$options = $this->_downloader->getOptions();
if (isset($options['offline'])) {
if (PEAR::isError($origErr) && !isset($options['soft'])) {
foreach ($origErr->getUserInfo() as $userInfo) {
if (isset($userInfo['message'])) {
$this->_downloader->log(0, $userInfo['message']);
}
}
$this->_downloader->log(0, $origErr->getMessage());
}
return PEAR::raiseError('Cannot download non-local package "' . $param . '"');
}
$err = $this->_fromUrl($param);
if (PEAR::isError($err) || !$this->_valid) {
if ($this->_type == 'url') {
if (PEAR::isError($err) && !isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
return PEAR::raiseError("Invalid or missing remote package file");
}
$err = $this->_fromString($param);
if (PEAR::isError($err) || !$this->_valid) {
if (PEAR::isError($err) && $err->getCode() == PEAR_DOWNLOADER_PACKAGE_STATE) {
return false; // instruct the downloader to silently skip
}
if (isset($this->_type) && $this->_type == 'local' && PEAR::isError($origErr)) {
if (is_array($origErr->getUserInfo())) {
foreach ($origErr->getUserInfo() as $err) {
if (is_array($err)) {
$err = $err['message'];
}
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err);
}
}
}
if (!isset($options['soft'])) {
$this->_downloader->log(0, $origErr->getMessage());
}
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param, true);
}
if (!isset($options['soft'])) {
$this->_downloader->log(2, "Cannot initialize '$param', invalid or missing package file");
}
// Passing no message back - already logged above
return PEAR::raiseError();
}
if (PEAR::isError($err) && !isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param, true);
}
if (!isset($options['soft'])) {
$this->_downloader->log(2, "Cannot initialize '$param', invalid or missing package file");
}
// Passing no message back - already logged above
return PEAR::raiseError();
}
}
return true;
}
/**
* Retrieve any non-local packages
* @return PEAR_PackageFile_v1|PEAR_PackageFile_v2|PEAR_Error
*/
function &download()
{
if (isset($this->_packagefile)) {
return $this->_packagefile;
}
if (isset($this->_downloadURL['url'])) {
$this->_isvalid = false;
$info = $this->getParsedPackage();
foreach ($info as $i => $p) {
$info[$i] = strtolower($p);
}
$err = $this->_fromUrl($this->_downloadURL['url'],
$this->_registry->parsedPackageNameToString($this->_parsedname, true));
$newinfo = $this->getParsedPackage();
foreach ($newinfo as $i => $p) {
$newinfo[$i] = strtolower($p);
}
if ($info != $newinfo) {
do {
if ($info['channel'] == 'pecl.php.net' && $newinfo['channel'] == 'pear.php.net') {
$info['channel'] = 'pear.php.net';
if ($info == $newinfo) {
// skip the channel check if a pecl package says it's a PEAR package
break;
}
}
if ($info['channel'] == 'pear.php.net' && $newinfo['channel'] == 'pecl.php.net') {
$info['channel'] = 'pecl.php.net';
if ($info == $newinfo) {
// skip the channel check if a pecl package says it's a PEAR package
break;
}
}
return PEAR::raiseError('CRITICAL ERROR: We are ' .
$this->_registry->parsedPackageNameToString($info) . ', but the file ' .
'downloaded claims to be ' .
$this->_registry->parsedPackageNameToString($this->getParsedPackage()));
} while (false);
}
if (PEAR::isError($err) || !$this->_valid) {
return $err;
}
}
$this->_type = 'local';
return $this->_packagefile;
}
function &getPackageFile()
{
return $this->_packagefile;
}
function &getDownloader()
{
return $this->_downloader;
}
function getType()
{
return $this->_type;
}
/**
* Like {@link initialize()}, but operates on a dependency
*/
function fromDepURL($dep)
{
$this->_downloadURL = $dep;
if (isset($dep['uri'])) {
$options = $this->_downloader->getOptions();
if (!extension_loaded("zlib") || isset($options['nocompress'])) {
$ext = '.tar';
} else {
$ext = '.tgz';
}
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$err = $this->_fromUrl($dep['uri'] . $ext);
PEAR::popErrorHandling();
if (PEAR::isError($err)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $err->getMessage());
}
return PEAR::raiseError('Invalid uri dependency "' . $dep['uri'] . $ext . '", ' .
'cannot download');
}
} else {
$this->_parsedname =
array(
'package' => $dep['info']->getPackage(),
'channel' => $dep['info']->getChannel(),
'version' => $dep['version']
);
if (!isset($dep['nodefault'])) {
$this->_parsedname['group'] = 'default'; // download the default dependency group
$this->_explicitGroup = false;
}
$this->_rawpackagefile = $dep['raw'];
}
}
function detectDependencies($params)
{
$options = $this->_downloader->getOptions();
if (isset($options['downloadonly'])) {
return;
}
if (isset($options['offline'])) {
$this->_downloader->log(3, 'Skipping dependency download check, --offline specified');
return;
}
$pname = $this->getParsedPackage();
if (!$pname) {
return;
}
$deps = $this->getDeps();
if (!$deps) {
return;
}
if (isset($deps['required'])) { // package.xml 2.0
return $this->_detect2($deps, $pname, $options, $params);
}
return $this->_detect1($deps, $pname, $options, $params);
}
function setValidated()
{
$this->_validated = true;
}
function alreadyValidated()
{
return $this->_validated;
}
/**
* Remove packages to be downloaded that are already installed
* @param array of PEAR_Downloader_Package objects
* @static
*/
function removeInstalled(&$params)
{
if (!isset($params[0])) {
return;
}
$options = $params[0]->_downloader->getOptions();
if (!isset($options['downloadonly'])) {
foreach ($params as $i => $param) {
$package = $param->getPackage();
$channel = $param->getChannel();
// remove self if already installed with this version
// this does not need any pecl magic - we only remove exact matches
if ($param->_installRegistry->packageExists($package, $channel)) {
$packageVersion = $param->_installRegistry->packageInfo($package, 'version', $channel);
if (version_compare($packageVersion, $param->getVersion(), '==')) {
if (!isset($options['force'])) {
$info = $param->getParsedPackage();
unset($info['version']);
unset($info['state']);
if (!isset($options['soft'])) {
$param->_downloader->log(1, 'Skipping package "' .
$param->getShortName() .
'", already installed as version ' . $packageVersion);
}
$params[$i] = false;
}
} elseif (!isset($options['force']) && !isset($options['upgrade']) &&
!isset($options['soft'])) {
$info = $param->getParsedPackage();
$param->_downloader->log(1, 'Skipping package "' .
$param->getShortName() .
'", already installed as version ' . $packageVersion);
$params[$i] = false;
}
}
}
}
PEAR_Downloader_Package::removeDuplicates($params);
}
function _detect2($deps, $pname, $options, $params)
{
$this->_downloadDeps = array();
$groupnotfound = false;
foreach (array('package', 'subpackage') as $packagetype) {
// get required dependency group
if (isset($deps['required'][$packagetype])) {
if (isset($deps['required'][$packagetype][0])) {
foreach ($deps['required'][$packagetype] as $dep) {
if (isset($dep['conflicts'])) {
// skip any package that this package conflicts with
continue;
}
$ret = $this->_detect2Dep($dep, $pname, 'required', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
} else {
$dep = $deps['required'][$packagetype];
if (!isset($dep['conflicts'])) {
// skip any package that this package conflicts with
$ret = $this->_detect2Dep($dep, $pname, 'required', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
}
}
// get optional dependency group, if any
if (isset($deps['optional'][$packagetype])) {
$skipnames = array();
if (!isset($deps['optional'][$packagetype][0])) {
$deps['optional'][$packagetype] = array($deps['optional'][$packagetype]);
}
foreach ($deps['optional'][$packagetype] as $dep) {
$skip = false;
if (!isset($options['alldeps'])) {
$dep['package'] = $dep['name'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, 'Notice: package "' .
$this->_registry->parsedPackageNameToString($this->getParsedPackage(),
true) . '" optional dependency "' .
$this->_registry->parsedPackageNameToString(array('package' =>
$dep['name'], 'channel' => 'pear.php.net'), true) .
'" will not be automatically downloaded');
}
$skipnames[] = $this->_registry->parsedPackageNameToString($dep, true);
$skip = true;
unset($dep['package']);
}
$ret = $this->_detect2Dep($dep, $pname, 'optional', $params);
if (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
if (!$ret) {
$dep['package'] = $dep['name'];
$skip = count($skipnames) ?
$skipnames[count($skipnames) - 1] : '';
if ($skip ==
$this->_registry->parsedPackageNameToString($dep, true)) {
array_pop($skipnames);
}
}
if (!$skip && is_array($ret)) {
$this->_downloadDeps[] = $ret;
}
}
if (count($skipnames)) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'Did not download optional dependencies: ' .
implode(', ', $skipnames) .
', use --alldeps to download automatically');
}
}
}
// get requested dependency group, if any
$groupname = $this->getGroup();
$explicit = $this->_explicitGroup;
if (!$groupname) {
if (!$this->canDefault()) {
continue;
}
$groupname = 'default'; // try the default dependency group
}
if ($groupnotfound) {
continue;
}
if (isset($deps['group'])) {
if (isset($deps['group']['attribs'])) {
if (strtolower($deps['group']['attribs']['name']) == strtolower($groupname)) {
$group = $deps['group'];
} elseif ($explicit) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, 'Warning: package "' .
$this->_registry->parsedPackageNameToString($pname, true) .
'" has no dependency ' . 'group named "' . $groupname . '"');
}
$groupnotfound = true;
continue;
}
} else {
$found = false;
foreach ($deps['group'] as $group) {
if (strtolower($group['attribs']['name']) == strtolower($groupname)) {
$found = true;
break;
}
}
if (!$found) {
if ($explicit) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, 'Warning: package "' .
$this->_registry->parsedPackageNameToString($pname, true) .
'" has no dependency ' . 'group named "' . $groupname . '"');
}
}
$groupnotfound = true;
continue;
}
}
}
if (isset($group) && isset($group[$packagetype])) {
if (isset($group[$packagetype][0])) {
foreach ($group[$packagetype] as $dep) {
$ret = $this->_detect2Dep($dep, $pname, 'dependency group "' .
$group['attribs']['name'] . '"', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
} else {
$ret = $this->_detect2Dep($group[$packagetype], $pname,
'dependency group "' .
$group['attribs']['name'] . '"', $params);
if (is_array($ret)) {
$this->_downloadDeps[] = $ret;
} elseif (PEAR::isError($ret) && !isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
}
}
}
}
function _detect2Dep($dep, $pname, $group, $params)
{
if (isset($dep['conflicts'])) {
return true;
}
$options = $this->_downloader->getOptions();
if (isset($dep['uri'])) {
return array('uri' => $dep['uri'], 'dep' => $dep);;
}
$testdep = $dep;
$testdep['package'] = $dep['name'];
if (PEAR_Downloader_Package::willDownload($testdep, $params)) {
$dep['package'] = $dep['name'];
if (!isset($options['soft'])) {
$this->_downloader->log(2, $this->getShortName() . ': Skipping ' . $group .
' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", will be installed');
}
return false;
}
$options = $this->_downloader->getOptions();
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if ($this->_explicitState) {
$pname['state'] = $this->_explicitState;
}
$url = $this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
if (PEAR::isError($url)) {
PEAR::popErrorHandling();
return $url;
}
$dep['package'] = $dep['name'];
$ret = $this->_analyzeDownloadURL($url, 'dependency', $dep, $params, $group == 'optional' &&
!isset($options['alldeps']), true);
PEAR::popErrorHandling();
if (PEAR::isError($ret)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
return false;
}
// check to see if a dep is already installed and is the same or newer
if (!isset($dep['min']) && !isset($dep['max']) && !isset($dep['recommended'])) {
$oper = 'has';
} else {
$oper = 'gt';
}
// do not try to move this before getDepPackageDownloadURL
// we can't determine whether upgrade is necessary until we know what
// version would be downloaded
if (!isset($options['force']) && $this->isInstalled($ret, $oper)) {
$version = $this->_installRegistry->packageInfo($dep['name'], 'version', $dep['channel']);
$dep['package'] = $dep['name'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group .
' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'" version ' . $url['version'] . ', already installed as version ' .
$version);
}
return false;
}
if (isset($dep['nodefault'])) {
$ret['nodefault'] = true;
}
return $ret;
}
function _detect1($deps, $pname, $options, $params)
{
$this->_downloadDeps = array();
$skipnames = array();
foreach ($deps as $dep) {
$nodownload = false;
if (isset ($dep['type']) && $dep['type'] === 'pkg') {
$dep['channel'] = 'pear.php.net';
$dep['package'] = $dep['name'];
switch ($dep['rel']) {
case 'not' :
continue 2;
case 'ge' :
case 'eq' :
case 'gt' :
case 'has' :
$group = (!isset($dep['optional']) || $dep['optional'] == 'no') ?
'required' :
'optional';
if (PEAR_Downloader_Package::willDownload($dep, $params)) {
$this->_downloader->log(2, $this->getShortName() . ': Skipping ' . $group
. ' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", will be installed');
continue 2;
}
$fakedp = new PEAR_PackageFile_v1;
$fakedp->setPackage($dep['name']);
// skip internet check if we are not upgrading (bug #5810)
if (!isset($options['upgrade']) && $this->isInstalled(
$fakedp, $dep['rel'])) {
$this->_downloader->log(2, $this->getShortName() . ': Skipping ' . $group
. ' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", is already installed');
continue 2;
}
}
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if ($this->_explicitState) {
$pname['state'] = $this->_explicitState;
}
$url = $this->_downloader->_getDepPackageDownloadUrl($dep, $pname);
$chan = 'pear.php.net';
if (PEAR::isError($url)) {
// check to see if this is a pecl package that has jumped
// from pear.php.net to pecl.php.net channel
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
$newdep = PEAR_Dependency2::normalizeDep($dep);
$newdep = $newdep[0];
$newdep['channel'] = 'pecl.php.net';
$chan = 'pecl.php.net';
$url = $this->_downloader->_getDepPackageDownloadUrl($newdep, $pname);
$obj = &$this->_installRegistry->getPackage($dep['name']);
if (PEAR::isError($url)) {
PEAR::popErrorHandling();
if ($obj !== null && $this->isInstalled($obj, $dep['rel'])) {
$group = (!isset($dep['optional']) || $dep['optional'] == 'no') ?
'required' :
'optional';
$dep['package'] = $dep['name'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, $this->getShortName() .
': Skipping ' . $group . ' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", already installed as version ' . $obj->getVersion());
}
$skip = count($skipnames) ?
$skipnames[count($skipnames) - 1] : '';
if ($skip ==
$this->_registry->parsedPackageNameToString($dep, true)) {
array_pop($skipnames);
}
continue;
} else {
if (isset($dep['optional']) && $dep['optional'] == 'yes') {
$this->_downloader->log(2, $this->getShortName() .
': Skipping optional dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", no releases exist');
continue;
} else {
return $url;
}
}
}
}
PEAR::popErrorHandling();
if (!isset($options['alldeps'])) {
if (isset($dep['optional']) && $dep['optional'] == 'yes') {
if (!isset($options['soft'])) {
$this->_downloader->log(3, 'Notice: package "' .
$this->getShortName() .
'" optional dependency "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $chan, 'package' =>
$dep['name']), true) .
'" will not be automatically downloaded');
}
$skipnames[] = $this->_registry->parsedPackageNameToString(
array('channel' => $chan, 'package' =>
$dep['name']), true);
$nodownload = true;
}
}
if (!isset($options['alldeps']) && !isset($options['onlyreqdeps'])) {
if (!isset($dep['optional']) || $dep['optional'] == 'no') {
if (!isset($options['soft'])) {
$this->_downloader->log(3, 'Notice: package "' .
$this->getShortName() .
'" required dependency "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $chan, 'package' =>
$dep['name']), true) .
'" will not be automatically downloaded');
}
$skipnames[] = $this->_registry->parsedPackageNameToString(
array('channel' => $chan, 'package' =>
$dep['name']), true);
$nodownload = true;
}
}
// check to see if a dep is already installed
// do not try to move this before getDepPackageDownloadURL
// we can't determine whether upgrade is necessary until we know what
// version would be downloaded
if (!isset($options['force']) && $this->isInstalled(
$url, $dep['rel'])) {
$group = (!isset($dep['optional']) || $dep['optional'] == 'no') ?
'required' :
'optional';
$dep['package'] = $dep['name'];
if (isset($newdep)) {
$version = $this->_installRegistry->packageInfo($newdep['name'], 'version', $newdep['channel']);
} else {
$version = $this->_installRegistry->packageInfo($dep['name'], 'version');
}
$dep['version'] = $url['version'];
if (!isset($options['soft'])) {
$this->_downloader->log(3, $this->getShortName() . ': Skipping ' . $group .
' dependency "' .
$this->_registry->parsedPackageNameToString($dep, true) .
'", already installed as version ' . $version);
}
$skip = count($skipnames) ?
$skipnames[count($skipnames) - 1] : '';
if ($skip ==
$this->_registry->parsedPackageNameToString($dep, true)) {
array_pop($skipnames);
}
continue;
}
if ($nodownload) {
continue;
}
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if (isset($newdep)) {
$dep = $newdep;
}
$dep['package'] = $dep['name'];
$ret = $this->_analyzeDownloadURL($url, 'dependency', $dep, $params,
isset($dep['optional']) && $dep['optional'] == 'yes' &&
!isset($options['alldeps']), true);
PEAR::popErrorHandling();
if (PEAR::isError($ret)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $ret->getMessage());
}
continue;
}
$this->_downloadDeps[] = $ret;
}
}
if (count($skipnames)) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'Did not download dependencies: ' .
implode(', ', $skipnames) .
', use --alldeps or --onlyreqdeps to download automatically');
}
}
}
function setDownloadURL($pkg)
{
$this->_downloadURL = $pkg;
}
/**
* Set the package.xml object for this downloaded package
*
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2 $pkg
*/
function setPackageFile(&$pkg)
{
$this->_packagefile = &$pkg;
}
function getShortName()
{
return $this->_registry->parsedPackageNameToString(array('channel' => $this->getChannel(),
'package' => $this->getPackage()), true);
}
function getParsedPackage()
{
if (isset($this->_packagefile) || isset($this->_parsedname)) {
return array('channel' => $this->getChannel(),
'package' => $this->getPackage(),
'version' => $this->getVersion());
}
return false;
}
function getDownloadURL()
{
return $this->_downloadURL;
}
function canDefault()
{
if (isset($this->_downloadURL) && isset($this->_downloadURL['nodefault'])) {
return false;
}
return true;
}
function getPackage()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getPackage();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getPackage();
}
return false;
}
/**
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
*/
function isSubpackage(&$pf)
{
if (isset($this->_packagefile)) {
return $this->_packagefile->isSubpackage($pf);
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->isSubpackage($pf);
}
return false;
}
function getPackageType()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getPackageType();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getPackageType();
}
return false;
}
function isBundle()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getPackageType() == 'bundle';
}
return false;
}
function getPackageXmlVersion()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getPackagexmlVersion();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getPackagexmlVersion();
}
return '1.0';
}
function getChannel()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getChannel();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getChannel();
}
return false;
}
function getURI()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getURI();
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->getURI();
}
return false;
}
function getVersion()
{
if (isset($this->_packagefile)) {
return $this->_packagefile->getVersion();
} elseif (isset($this->_downloadURL['version'])) {
return $this->_downloadURL['version'];
}
return false;
}
function isCompatible($pf)
{
if (isset($this->_packagefile)) {
return $this->_packagefile->isCompatible($pf);
} elseif (isset($this->_downloadURL['info'])) {
return $this->_downloadURL['info']->isCompatible($pf);
}
return true;
}
function setGroup($group)
{
$this->_parsedname['group'] = $group;
}
function getGroup()
{
if (isset($this->_parsedname['group'])) {
return $this->_parsedname['group'];
}
return '';
}
function isExtension($name)
{
if (isset($this->_packagefile)) {
return $this->_packagefile->isExtension($name);
} elseif (isset($this->_downloadURL['info'])) {
if ($this->_downloadURL['info']->getPackagexmlVersion() == '2.0') {
return $this->_downloadURL['info']->getProvidesExtension() == $name;
}
return false;
}
return false;
}
function getDeps()
{
if (isset($this->_packagefile)) {
$ver = $this->_packagefile->getPackagexmlVersion();
if (version_compare($ver, '2.0', '>=')) {
return $this->_packagefile->getDeps(true);
}
return $this->_packagefile->getDeps();
} elseif (isset($this->_downloadURL['info'])) {
$ver = $this->_downloadURL['info']->getPackagexmlVersion();
if (version_compare($ver, '2.0', '>=')) {
return $this->_downloadURL['info']->getDeps(true);
}
return $this->_downloadURL['info']->getDeps();
}
return array();
}
/**
* @param array Parsed array from {@link PEAR_Registry::parsePackageName()} or a dependency
* returned from getDepDownloadURL()
*/
function isEqual($param)
{
if (is_object($param)) {
$channel = $param->getChannel();
$package = $param->getPackage();
if ($param->getURI()) {
$param = array(
'channel' => $param->getChannel(),
'package' => $param->getPackage(),
'version' => $param->getVersion(),
'uri' => $param->getURI(),
);
} else {
$param = array(
'channel' => $param->getChannel(),
'package' => $param->getPackage(),
'version' => $param->getVersion(),
);
}
} else {
if (isset($param['uri'])) {
if ($this->getChannel() != '__uri') {
return false;
}
return $param['uri'] == $this->getURI();
}
$package = isset($param['package']) ? $param['package'] : $param['info']->getPackage();
$channel = isset($param['channel']) ? $param['channel'] : $param['info']->getChannel();
if (isset($param['rel'])) {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
$newdep = PEAR_Dependency2::normalizeDep($param);
$newdep = $newdep[0];
} elseif (isset($param['min'])) {
$newdep = $param;
}
}
if (isset($newdep)) {
if (!isset($newdep['min'])) {
$newdep['min'] = '0';
}
if (!isset($newdep['max'])) {
$newdep['max'] = '100000000000000000000';
}
// use magic to support pecl packages suddenly jumping to the pecl channel
// we need to support both dependency possibilities
if ($channel == 'pear.php.net' && $this->getChannel() == 'pecl.php.net') {
if ($package == $this->getPackage()) {
$channel = 'pecl.php.net';
}
}
if ($channel == 'pecl.php.net' && $this->getChannel() == 'pear.php.net') {
if ($package == $this->getPackage()) {
$channel = 'pear.php.net';
}
}
return (strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel() &&
version_compare($newdep['min'], $this->getVersion(), '<=') &&
version_compare($newdep['max'], $this->getVersion(), '>='));
}
// use magic to support pecl packages suddenly jumping to the pecl channel
if ($channel == 'pecl.php.net' && $this->getChannel() == 'pear.php.net') {
if (strtolower($package) == strtolower($this->getPackage())) {
$channel = 'pear.php.net';
}
}
if (isset($param['version'])) {
return (strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel() &&
$param['version'] == $this->getVersion());
}
return strtolower($package) == strtolower($this->getPackage()) &&
$channel == $this->getChannel();
}
function isInstalled($dep, $oper = '==')
{
if (!$dep) {
return false;
}
if ($oper != 'ge' && $oper != 'gt' && $oper != 'has' && $oper != '==') {
return false;
}
if (is_object($dep)) {
$package = $dep->getPackage();
$channel = $dep->getChannel();
if ($dep->getURI()) {
$dep = array(
'uri' => $dep->getURI(),
'version' => $dep->getVersion(),
);
} else {
$dep = array(
'version' => $dep->getVersion(),
);
}
} else {
if (isset($dep['uri'])) {
$channel = '__uri';
$package = $dep['dep']['name'];
} else {
$channel = $dep['info']->getChannel();
$package = $dep['info']->getPackage();
}
}
$options = $this->_downloader->getOptions();
$test = $this->_installRegistry->packageExists($package, $channel);
if (!$test && $channel == 'pecl.php.net') {
// do magic to allow upgrading from old pecl packages to new ones
$test = $this->_installRegistry->packageExists($package, 'pear.php.net');
$channel = 'pear.php.net';
}
if ($test) {
if (isset($dep['uri'])) {
if ($this->_installRegistry->packageInfo($package, 'uri', '__uri') == $dep['uri']) {
return true;
}
}
if (isset($options['upgrade'])) {
$packageVersion = $this->_installRegistry->packageInfo($package, 'version', $channel);
if (version_compare($packageVersion, $dep['version'], '>=')) {
return true;
}
return false;
}
return true;
}
return false;
}
/**
* Detect duplicate package names with differing versions
*
* If a user requests to install Date 1.4.6 and Date 1.4.7,
* for instance, this is a logic error. This method
* detects this situation.
*
* @param array $params array of PEAR_Downloader_Package objects
* @param array $errorparams empty array
* @return array array of stupid duplicated packages in PEAR_Downloader_Package obejcts
*/
function detectStupidDuplicates($params, &$errorparams)
{
$existing = array();
foreach ($params as $i => $param) {
$package = $param->getPackage();
$channel = $param->getChannel();
$group = $param->getGroup();
if (!isset($existing[$channel . '/' . $package])) {
$existing[$channel . '/' . $package] = array();
}
if (!isset($existing[$channel . '/' . $package][$group])) {
$existing[$channel . '/' . $package][$group] = array();
}
$existing[$channel . '/' . $package][$group][] = $i;
}
$indices = array();
foreach ($existing as $package => $groups) {
foreach ($groups as $group => $dupes) {
if (count($dupes) > 1) {
$indices = $indices + $dupes;
}
}
}
$indices = array_unique($indices);
foreach ($indices as $index) {
$errorparams[] = $params[$index];
}
return count($errorparams);
}
/**
* @param array
* @param bool ignore install groups - for final removal of dupe packages
* @static
*/
function removeDuplicates(&$params, $ignoreGroups = false)
{
$pnames = array();
foreach ($params as $i => $param) {
if (!$param) {
continue;
}
if ($param->getPackage()) {
$group = $ignoreGroups ? '' : $param->getGroup();
$pnames[$i] = $param->getChannel() . '/' .
$param->getPackage() . '-' . $param->getVersion() . '#' . $group;
}
}
$pnames = array_unique($pnames);
$unset = array_diff(array_keys($params), array_keys($pnames));
$testp = array_flip($pnames);
foreach ($params as $i => $param) {
if (!$param) {
$unset[] = $i;
continue;
}
if (!is_a($param, 'PEAR_Downloader_Package')) {
$unset[] = $i;
continue;
}
$group = $ignoreGroups ? '' : $param->getGroup();
if (!isset($testp[$param->getChannel() . '/' . $param->getPackage() . '-' .
$param->getVersion() . '#' . $group])) {
$unset[] = $i;
}
}
foreach ($unset as $i) {
unset($params[$i]);
}
$ret = array();
foreach ($params as $i => $param) {
$ret[] = &$params[$i];
}
$params = array();
foreach ($ret as $i => $param) {
$params[] = &$ret[$i];
}
}
function explicitState()
{
return $this->_explicitState;
}
function setExplicitState($s)
{
$this->_explicitState = $s;
}
/**
* @static
*/
function mergeDependencies(&$params)
{
$bundles = $newparams = array();
foreach ($params as $i => $param) {
if (!$param->isBundle()) {
continue;
}
$bundles[] = $i;
$pf = &$param->getPackageFile();
$newdeps = array();
$contents = $pf->getBundledPackages();
if (!is_array($contents)) {
$contents = array($contents);
}
foreach ($contents as $file) {
$filecontents = $pf->getFileContents($file);
$dl = &$param->getDownloader();
$options = $dl->getOptions();
if (PEAR::isError($dir = $dl->getDownloadDir())) {
return $dir;
}
$fp = @fopen($dir . DIRECTORY_SEPARATOR . $file, 'wb');
if (!$fp) {
continue;
}
// FIXME do symlink check
fwrite($fp, $filecontents, strlen($filecontents));
fclose($fp);
if ($s = $params[$i]->explicitState()) {
$obj->setExplicitState($s);
}
$obj = &new PEAR_Downloader_Package($params[$i]->getDownloader());
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
if (PEAR::isError($dir = $dl->getDownloadDir())) {
PEAR::popErrorHandling();
return $dir;
}
$e = $obj->_fromFile($a = $dir . DIRECTORY_SEPARATOR . $file);
PEAR::popErrorHandling();
if (PEAR::isError($e)) {
if (!isset($options['soft'])) {
$dl->log(0, $e->getMessage());
}
continue;
}
$j = &$obj;
if (!PEAR_Downloader_Package::willDownload($j,
array_merge($params, $newparams)) && !$param->isInstalled($j)) {
$newparams[] = &$j;
}
}
}
foreach ($bundles as $i) {
unset($params[$i]); // remove bundles - only their contents matter for installation
}
PEAR_Downloader_Package::removeDuplicates($params); // strip any unset indices
if (count($newparams)) { // add in bundled packages for install
foreach ($newparams as $i => $unused) {
$params[] = &$newparams[$i];
}
$newparams = array();
}
foreach ($params as $i => $param) {
$newdeps = array();
foreach ($param->_downloadDeps as $dep) {
$merge = array_merge($params, $newparams);
if (!PEAR_Downloader_Package::willDownload($dep, $merge)
&& !$param->isInstalled($dep)
) {
$newdeps[] = $dep;
} else {
//var_dump($dep);
// detect versioning conflicts here
}
}
// convert the dependencies into PEAR_Downloader_Package objects for the next time around
$params[$i]->_downloadDeps = array();
foreach ($newdeps as $dep) {
$obj = &new PEAR_Downloader_Package($params[$i]->getDownloader());
if ($s = $params[$i]->explicitState()) {
$obj->setExplicitState($s);
}
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$e = $obj->fromDepURL($dep);
PEAR::popErrorHandling();
if (PEAR::isError($e)) {
if (!isset($options['soft'])) {
$obj->_downloader->log(0, $e->getMessage());
}
continue;
}
$e = $obj->detectDependencies($params);
if (PEAR::isError($e)) {
if (!isset($options['soft'])) {
$obj->_downloader->log(0, $e->getMessage());
}
}
$j = &$obj;
$newparams[] = &$j;
}
}
if (count($newparams)) {
foreach ($newparams as $i => $unused) {
$params[] = &$newparams[$i];
}
return true;
}
return false;
}
/**
* @static
*/
function willDownload($param, $params)
{
if (!is_array($params)) {
return false;
}
foreach ($params as $obj) {
if ($obj->isEqual($param)) {
return true;
}
}
return false;
}
/**
* For simpler unit-testing
* @param PEAR_Config
* @param int
* @param string
*/
function &getPackagefileObject(&$c, $d)
{
$a = &new PEAR_PackageFile($c, $d);
return $a;
}
/**
* This will retrieve from a local file if possible, and parse out
* a group name as well. The original parameter will be modified to reflect this.
* @param string|array can be a parsed package name as well
* @access private
*/
function _fromFile(&$param)
{
$saveparam = $param;
if (is_string($param)) {
if (!@file_exists($param)) {
$test = explode('#', $param);
$group = array_pop($test);
if (@file_exists(implode('#', $test))) {
$this->setGroup($group);
$param = implode('#', $test);
$this->_explicitGroup = true;
}
}
if (@is_file($param)) {
$this->_type = 'local';
$options = $this->_downloader->getOptions();
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->_debug);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($param, PEAR_VALIDATE_INSTALLING);
PEAR::popErrorHandling();
if (PEAR::isError($pf)) {
$this->_valid = false;
$param = $saveparam;
return $pf;
}
$this->_packagefile = &$pf;
if (!$this->getGroup()) {
$this->setGroup('default'); // install the default dependency group
}
return $this->_valid = true;
}
}
$param = $saveparam;
return $this->_valid = false;
}
function _fromUrl($param, $saveparam = '')
{
if (!is_array($param) && (preg_match('#^(http|https|ftp)://#', $param))) {
$options = $this->_downloader->getOptions();
$this->_type = 'url';
$callback = $this->_downloader->ui ?
array(&$this->_downloader, '_downloadCallback') : null;
$this->_downloader->pushErrorHandling(PEAR_ERROR_RETURN);
if (PEAR::isError($dir = $this->_downloader->getDownloadDir())) {
$this->_downloader->popErrorHandling();
return $dir;
}
$this->_downloader->log(3, 'Downloading "' . $param . '"');
$file = $this->_downloader->downloadHttp($param, $this->_downloader->ui,
$dir, $callback, null, false, $this->getChannel());
$this->_downloader->popErrorHandling();
if (PEAR::isError($file)) {
if (!empty($saveparam)) {
$saveparam = ", cannot download \"$saveparam\"";
}
$err = PEAR::raiseError('Could not download from "' . $param .
'"' . $saveparam . ' (' . $file->getMessage() . ')');
return $err;
}
if ($this->_rawpackagefile) {
require_once 'Archive/Tar.php';
$tar = &new Archive_Tar($file);
$packagexml = $tar->extractInString('package2.xml');
if (!$packagexml) {
$packagexml = $tar->extractInString('package.xml');
}
if (str_replace(array("\n", "\r"), array('',''), $packagexml) !=
str_replace(array("\n", "\r"), array('',''), $this->_rawpackagefile)) {
if ($this->getChannel() != 'pear.php.net') {
return PEAR::raiseError('CRITICAL ERROR: package.xml downloaded does ' .
'not match value returned from xml-rpc');
}
// be more lax for the existing PEAR packages that have not-ok
// characters in their package.xml
$this->_downloader->log(0, 'CRITICAL WARNING: The "' .
$this->getPackage() . '" package has invalid characters in its ' .
'package.xml. The next version of PEAR may not be able to install ' .
'this package for security reasons. Please open a bug report at ' .
'http://pear.php.net/package/' . $this->getPackage() . '/bugs');
}
}
// whew, download worked!
$pkg = &$this->getPackagefileObject($this->_config, $this->_downloader->debug);
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pf = &$pkg->fromAnyFile($file, PEAR_VALIDATE_INSTALLING);
PEAR::popErrorHandling();
if (PEAR::isError($pf)) {
if (is_array($pf->getUserInfo())) {
foreach ($pf->getUserInfo() as $err) {
if (is_array($err)) {
$err = $err['message'];
}
if (!isset($options['soft'])) {
$this->_downloader->log(0, "Validation Error: $err");
}
}
}
if (!isset($options['soft'])) {
$this->_downloader->log(0, $pf->getMessage());
}
///FIXME need to pass back some error code that we can use to match with to cancel all further operations
/// At least stop all deps of this package from being installed
$out = $saveparam ? $saveparam : $param;
$err = PEAR::raiseError('Download of "' . $out . '" succeeded, but it is not a valid package archive');
$this->_valid = false;
return $err;
}
$this->_packagefile = &$pf;
$this->setGroup('default'); // install the default dependency group
return $this->_valid = true;
}
return $this->_valid = false;
}
/**
*
* @param string|array pass in an array of format
* array(
* 'package' => 'pname',
* ['channel' => 'channame',]
* ['version' => 'version',]
* ['state' => 'state',])
* or a string of format [channame/]pname[-version|-state]
*/
function _fromString($param)
{
$options = $this->_downloader->getOptions();
$channel = $this->_config->get('default_channel');
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pname = $this->_registry->parsePackageName($param, $channel);
PEAR::popErrorHandling();
if (PEAR::isError($pname)) {
if ($pname->getCode() == 'invalid') {
$this->_valid = false;
return false;
}
if ($pname->getCode() == 'channel') {
$parsed = $pname->getUserInfo();
if ($this->_downloader->discover($parsed['channel'])) {
if ($this->_config->get('auto_discover')) {
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$pname = $this->_registry->parsePackageName($param, $channel);
PEAR::popErrorHandling();
} else {
if (!isset($options['soft'])) {
$this->_downloader->log(0, 'Channel "' . $parsed['channel'] .
'" is not initialized, use ' .
'"pear channel-discover ' . $parsed['channel'] . '" to initialize' .
'or pear config-set auto_discover 1');
}
}
}
if (PEAR::isError($pname)) {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $pname->getMessage());
}
if (is_array($param)) {
$param = $this->_registry->parsedPackageNameToString($param);
}
$err = PEAR::raiseError('invalid package name/package file "' . $param . '"');
$this->_valid = false;
return $err;
}
} else {
if (!isset($options['soft'])) {
$this->_downloader->log(0, $pname->getMessage());
}
$err = PEAR::raiseError('invalid package name/package file "' . $param . '"');
$this->_valid = false;
return $err;
}
}
if (!isset($this->_type)) {
$this->_type = 'rest';
}
$this->_parsedname = $pname;
$this->_explicitState = isset($pname['state']) ? $pname['state'] : false;
$this->_explicitGroup = isset($pname['group']) ? true : false;
$info = $this->_downloader->_getPackageDownloadUrl($pname);
if (PEAR::isError($info)) {
if ($info->getCode() != -976 && $pname['channel'] == 'pear.php.net') {
// try pecl
$pname['channel'] = 'pecl.php.net';
if ($test = $this->_downloader->_getPackageDownloadUrl($pname)) {
if (!PEAR::isError($test)) {
$info = PEAR::raiseError($info->getMessage() . ' - package ' .
$this->_registry->parsedPackageNameToString($pname, true) .
' can be installed with "pecl install ' . $pname['package'] .
'"');
} else {
$pname['channel'] = 'pear.php.net';
}
} else {
$pname['channel'] = 'pear.php.net';
}
}
return $info;
}
$this->_rawpackagefile = $info['raw'];
$ret = $this->_analyzeDownloadURL($info, $param, $pname);
if (PEAR::isError($ret)) {
return $ret;
}
if ($ret) {
$this->_downloadURL = $ret;
return $this->_valid = (bool) $ret;
}
}
/**
* @param array output of package.getDownloadURL
* @param string|array|object information for detecting packages to be downloaded, and
* for errors
* @param array name information of the package
* @param array|null packages to be downloaded
* @param bool is this an optional dependency?
* @param bool is this any kind of dependency?
* @access private
*/
function _analyzeDownloadURL($info, $param, $pname, $params = null, $optional = false,
$isdependency = false)
{
if (!is_string($param) && PEAR_Downloader_Package::willDownload($param, $params)) {
return false;
}
if ($info === false) {
$saveparam = !is_string($param) ? ", cannot download \"$param\"" : '';
// no releases exist
return PEAR::raiseError('No releases for package "' .
$this->_registry->parsedPackageNameToString($pname, true) . '" exist' . $saveparam);
}
if (strtolower($info['info']->getChannel()) != strtolower($pname['channel'])) {
$err = false;
if ($pname['channel'] == 'pecl.php.net') {
if ($info['info']->getChannel() != 'pear.php.net') {
$err = true;
}
} elseif ($info['info']->getChannel() == 'pecl.php.net') {
if ($pname['channel'] != 'pear.php.net') {
$err = true;
}
} else {
$err = true;
}
if ($err) {
return PEAR::raiseError('SECURITY ERROR: package in channel "' . $pname['channel'] .
'" retrieved another channel\'s name for download! ("' .
$info['info']->getChannel() . '")');
}
}
$preferred_state = $this->_config->get('preferred_state');
if (!isset($info['url'])) {
$package_version = $this->_registry->packageInfo($info['info']->getPackage(),
'version', $info['info']->getChannel());
if ($this->isInstalled($info)) {
if ($isdependency && version_compare($info['version'], $package_version, '<=')) {
// ignore bogus errors of "failed to download dependency"
// if it is already installed and the one that would be
// downloaded is older or the same version (Bug #7219)
return false;
}
}
if ($info['version'] === $package_version) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] .
'/' . $pname['package'] . '-' . $package_version. ', additionally the suggested version' .
' (' . $package_version . ') is the same as the locally installed one.');
}
return false;
}
if (version_compare($info['version'], $package_version, '<=')) {
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] .
'/' . $pname['package'] . '-' . $package_version . ', additionally the suggested version' .
' (' . $info['version'] . ') is a lower version than the locally installed one (' . $package_version . ').');
}
return false;
}
$instead = ', will instead download version ' . $info['version'] .
', stability "' . $info['info']->getState() . '"';
// releases exist, but we failed to get any
if (isset($this->_downloader->_options['force'])) {
if (isset($pname['version'])) {
$vs = ', version "' . $pname['version'] . '"';
} elseif (isset($pname['state'])) {
$vs = ', stability "' . $pname['state'] . '"';
} elseif ($param == 'dependency') {
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
if (!in_array($info['info']->getState(),
PEAR_Common::betterStates($preferred_state, true))) {
if ($optional) {
// don't spit out confusing error message
return $this->_downloader->_getPackageDownloadUrl(
array('package' => $pname['package'],
'channel' => $pname['channel'],
'version' => $info['version']));
}
$vs = ' within preferred state "' . $preferred_state .
'"';
} else {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
if ($optional) {
// don't spit out confusing error message
return $this->_downloader->_getPackageDownloadUrl(
array('package' => $pname['package'],
'channel' => $pname['channel'],
'version' => $info['version']));
}
$vs = PEAR_Dependency2::_getExtraString($pname);
$instead = '';
}
} else {
$vs = ' within preferred state "' . $preferred_state . '"';
}
if (!isset($options['soft'])) {
$this->_downloader->log(1, 'WARNING: failed to download ' . $pname['channel'] .
'/' . $pname['package'] . $vs . $instead);
}
// download the latest release
return $this->_downloader->_getPackageDownloadUrl(
array('package' => $pname['package'],
'channel' => $pname['channel'],
'version' => $info['version']));
} else {
if (isset($info['php']) && $info['php']) {
$err = PEAR::raiseError('Failed to download ' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'],
'package' => $pname['package']),
true) .
', latest release is version ' . $info['php']['v'] .
', but it requires PHP version "' .
$info['php']['m'] . '", use "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package'],
'version' => $info['php']['v'])) . '" to install',
PEAR_DOWNLOADER_PACKAGE_PHPVERSION);
return $err;
}
// construct helpful error message
if (isset($pname['version'])) {
$vs = ', version "' . $pname['version'] . '"';
} elseif (isset($pname['state'])) {
$vs = ', stability "' . $pname['state'] . '"';
} elseif ($param == 'dependency') {
if (!class_exists('PEAR_Common')) {
require_once 'PEAR/Common.php';
}
if (!in_array($info['info']->getState(),
PEAR_Common::betterStates($preferred_state, true))) {
if ($optional) {
// don't spit out confusing error message, and don't die on
// optional dep failure!
return $this->_downloader->_getPackageDownloadUrl(
array('package' => $pname['package'],
'channel' => $pname['channel'],
'version' => $info['version']));
}
$vs = ' within preferred state "' . $preferred_state . '"';
} else {
if (!class_exists('PEAR_Dependency2')) {
require_once 'PEAR/Dependency2.php';
}
if ($optional) {
// don't spit out confusing error message, and don't die on
// optional dep failure!
return $this->_downloader->_getPackageDownloadUrl(
array('package' => $pname['package'],
'channel' => $pname['channel'],
'version' => $info['version']));
}
$vs = PEAR_Dependency2::_getExtraString($pname);
}
} else {
$vs = ' within preferred state "' . $this->_downloader->config->get('preferred_state') . '"';
}
$options = $this->_downloader->getOptions();
// this is only set by the "download-all" command
if (isset($options['ignorepreferred_state'])) {
$err = PEAR::raiseError(
'Failed to download ' . $this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package']),
true)
. $vs .
', latest release is version ' . $info['version'] .
', stability "' . $info['info']->getState() . '", use "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package'],
'version' => $info['version'])) . '" to install',
PEAR_DOWNLOADER_PACKAGE_STATE);
return $err;
}
// Checks if the user has a package installed already and checks the release against
// the state against the installed package, this allows upgrades for packages
// with lower stability than the preferred_state
$stability = $this->_registry->packageInfo($pname['package'], 'stability', $pname['channel']);
if (!$this->isInstalled($info)
|| !in_array($info['info']->getState(), PEAR_Common::betterStates($stability['release'], true))
) {
$err = PEAR::raiseError(
'Failed to download ' . $this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package']),
true)
. $vs .
', latest release is version ' . $info['version'] .
', stability "' . $info['info']->getState() . '", use "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $pname['channel'], 'package' => $pname['package'],
'version' => $info['version'])) . '" to install');
return $err;
}
}
}
if (isset($info['deprecated']) && $info['deprecated']) {
$this->_downloader->log(0,
'WARNING: "' .
$this->_registry->parsedPackageNameToString(
array('channel' => $info['info']->getChannel(),
'package' => $info['info']->getPackage()), true) .
'" is deprecated in favor of "' .
$this->_registry->parsedPackageNameToString($info['deprecated'], true) .
'"');
}
return $info;
}
}
|