Revision b1360be3
src/etc/inc/pkg-utils.inc | ||
---|---|---|
59 | 59 |
return preg_match($pattern, $pkgname); |
60 | 60 |
} |
61 | 61 |
|
62 |
/* Remove pkg_prefix from package name if it's present */ |
|
62 |
/* Remove pkg_prefix or flavor_prefix from package name if it's present */
|
|
63 | 63 |
function pkg_remove_prefix(&$pkg_name) { |
64 |
global $g; |
|
65 |
|
|
66 |
if (substr($pkg_name, 0, strlen(g_get('pkg_prefix'))) == |
|
67 |
g_get('pkg_prefix')) { |
|
68 |
$pkg_name = substr($pkg_name, strlen(g_get('pkg_prefix'))); |
|
64 |
$pres = [g_get('pkg_prefix')]; |
|
65 |
if (!is_null(g_get('flavor_prefix'))) { |
|
66 |
$pres[] = g_get('flavor_prefix'); |
|
67 |
} |
|
68 |
foreach ( $pres as $pre) { |
|
69 |
if (str_starts_with($pkg_name, $pre)) { |
|
70 |
$pkg_name = substr($pkg_name, strlen($pre)); |
|
71 |
break; |
|
72 |
} |
|
69 | 73 |
} |
70 | 74 |
} |
71 | 75 |
|
... | ... | |
1556 | 1560 |
function update_repos() { |
1557 | 1561 |
$product_name = g_get('product_name'); |
1558 | 1562 |
$pipes = []; |
1559 |
$descriptorspec = [
|
|
1560 |
1 => ["pipe", "w"], /* stdout */
|
|
1561 |
2 => ["pipe", "w"] /* stderr */
|
|
1563 |
$dspec = [ |
|
1564 |
1 => ['pipe', 'w'], /* stdout */
|
|
1565 |
2 => ['pipe', 'w'] /* stderr */
|
|
1562 | 1566 |
]; |
1563 | 1567 |
$rc = -1; |
1564 | 1568 |
/* Default error message for failure cases. */ |
1565 | 1569 |
$fail_error = [ |
1566 | 1570 |
"error" => 1, |
1567 |
"messages" => ["Could not update connect to Netgate servers. Please try again later."]
|
|
1571 |
"messages" => [gettext('Could not connect to Netgate servers. Please try again later.')]
|
|
1568 | 1572 |
]; |
1569 | 1573 |
|
1570 | 1574 |
/* Execute repoc with a full pkg style environment, including proxy |
1571 | 1575 |
* configuration. */ |
1572 | 1576 |
$process = proc_open(sprintf('/usr/local/sbin/%s-repoc -N', $product_name), |
1573 |
$descriptorspec, $pipes, '/', pkg_env());
|
|
1577 |
$dspec, $pipes, '/', pkg_env()); |
|
1574 | 1578 |
|
1575 | 1579 |
/* Process failed to start */ |
1576 | 1580 |
if (!is_resource($process)) { |
1577 | 1581 |
return $fail_error; |
1578 | 1582 |
} |
1579 | 1583 |
|
1580 |
/* Read output */ |
|
1581 |
$stdout = stream_get_contents($pipes[1]); |
|
1582 |
fclose($pipes[1]); |
|
1583 |
/* If stdout is boolean false, reading stdout failed. */ |
|
1584 |
if ($stdout === false) { |
|
1585 |
return $fail_error; |
|
1586 |
} |
|
1587 |
|
|
1588 |
/* Read errors */ |
|
1589 |
$stderr = stream_get_contents($pipes[2]); |
|
1590 |
fclose($pipes[2]); |
|
1584 |
$timeout = 5; /* seconds */ |
|
1585 |
$stdout = ''; |
|
1586 |
do { |
|
1587 |
$start = microtime(true); |
|
1588 |
$r = ['stdout' => $pipes[1], 'stderr' => $pipes[2]]; |
|
1589 |
$w = $e = null; |
|
1590 |
if (($n = stream_select($r, $w, $e, 0)) === false) { |
|
1591 |
$result = $fail_error; |
|
1592 |
goto error; |
|
1593 |
} else if ($n > 0) { |
|
1594 |
foreach ($r as $var => $fd) { |
|
1595 |
$$var .= fread($fd, 4096); |
|
1596 |
} |
|
1597 |
} |
|
1598 |
if (($timeout -= (microtime(true) - $start)) <= 0) { |
|
1599 |
$result = $fail_error; |
|
1600 |
goto error; |
|
1601 |
} |
|
1602 |
} while (!feof($pipes[1]) && !feof($pipes[2])); |
|
1591 | 1603 |
|
1592 | 1604 |
/* Get return code */ |
1593 |
$rc = proc_close($process); |
|
1594 | 1605 |
$result = [ |
1595 |
"error" => $rc,
|
|
1606 |
"error" => proc_close($process),
|
|
1596 | 1607 |
"messages" => [] |
1597 | 1608 |
]; |
1598 | 1609 |
|
... | ... | |
1600 | 1611 |
$stdout = explode("\n", trim($stdout)); |
1601 | 1612 |
|
1602 | 1613 |
if ((count($stdout) > 1) && |
1603 |
($stdout[0] === "Messages:")) {
|
|
1614 |
($stdout[0] === 'Messages:')) {
|
|
1604 | 1615 |
/* Copy over message content from the output. */ |
1605 | 1616 |
$result['messages'] = array_merge($result['messages'], array_slice($stdout, 1)); |
1606 | 1617 |
} elseif (!empty($stderr)) { |
1607 | 1618 |
$result['messages'][] = $stderr; |
1608 | 1619 |
} |
1609 | 1620 |
|
1610 |
return ($result); |
|
1621 |
error: |
|
1622 |
if (is_resource($process)) { |
|
1623 |
proc_close($process); |
|
1624 |
} |
|
1625 |
|
|
1626 |
return $result; |
|
1611 | 1627 |
} |
1612 | 1628 |
?> |
Also available in: Unified diff
Clean up diffs