Revision 645f2fa8
Added by Phil Davis almost 10 years ago
etc/inc/pkg-utils.inc | ||
---|---|---|
87 | 87 |
conf_mount_ro(); |
88 | 88 |
} |
89 | 89 |
|
90 |
// Use a longer (30 second) connect timeout when trying to download each package file. |
|
91 |
// Package installs are not holding up general boot and routing/firewall functionality, |
|
92 |
// so it is nicer to wait a while if necessary rather than abort. |
|
93 |
define('PKG_FILE_DOWNLOAD_CONNECT_TIMEOUT', '30'); |
|
94 |
|
|
90 | 95 |
/****f* pkg-utils/remove_package |
91 | 96 |
* NAME |
92 | 97 |
* remove_package - Removes package from FreeBSD if it exists |
... | ... | |
497 | 502 |
$base_url = substr($base_url, 0, -1); |
498 | 503 |
$fetchto = "{$fetchdir}/apkg_{$filename}"; |
499 | 504 |
$static_output .= "\n" . str_repeat(" ", $dependlevel * 2 + 1) . "Downloading {$base_url}/{$filename} ... "; |
500 |
if (download_file_with_progress_bar("{$base_url}/{$filename}", $fetchto) !== true) { |
|
501 |
if ($base_url != $priv_url && download_file_with_progress_bar("{$priv_url}/{$filename}", $fetchto) !== true) { |
|
505 |
if (download_file_with_progress_bar("{$base_url}/{$filename}", $fetchto, "read_body", PKG_FILE_DOWNLOAD_CONNECT_TIMEOUT) !== true) {
|
|
506 |
if ($base_url != $priv_url && download_file_with_progress_bar("{$priv_url}/{$filename}", $fetchto, "read_body", PKG_FILE_DOWNLOAD_CONNECT_TIMEOUT) !== true) {
|
|
502 | 507 |
$static_output .= " could not download from there or {$priv_url}/{$filename}.\n"; |
503 | 508 |
update_output_window($static_output); |
504 | 509 |
return false; |
... | ... | |
770 | 775 |
update_output_window($static_output); |
771 | 776 |
} |
772 | 777 |
|
773 |
pkg_fetch_additional_files($pkg, $pkg_info); |
|
778 |
if (!pkg_fetch_additional_files($pkg, $pkg_info)) { |
|
779 |
return false; |
|
780 |
} |
|
774 | 781 |
|
775 | 782 |
/* if a require exists, include it. this will |
776 | 783 |
* show us where an error exists in a package |
... | ... | |
1448 | 1455 |
update_output_window($static_output); |
1449 | 1456 |
pkg_debug(gettext("Downloading package configuration file...") . "\n"); |
1450 | 1457 |
$fetchto = substr(strrchr($pkg_info['config_file'], '/'), 1); |
1451 |
download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto); |
|
1452 |
if(!file_exists('/usr/local/pkg/' . $fetchto)) { |
|
1458 |
if (download_file_with_progress_bar($pkg_info['config_file'], '/usr/local/pkg/' . $fetchto, "read_body", PKG_FILE_DOWNLOAD_CONNECT_TIMEOUT) !== true) { |
|
1453 | 1459 |
pkg_debug(gettext("ERROR! Unable to fetch package configuration file. Aborting installation.") . "\n"); |
1454 | 1460 |
if($pkg_interface == "console") |
1455 | 1461 |
print "\n" . gettext("ERROR! Unable to fetch package configuration file. Aborting package installation.") . "\n"; |
... | ... | |
1510 | 1516 |
safe_mkdir($prefix); |
1511 | 1517 |
$static_output .= $filename . " "; |
1512 | 1518 |
update_output_window($static_output); |
1513 |
if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename) !== true) { |
|
1519 |
if (download_file_with_progress_bar($afn['item'][0], $prefix . $filename, "read_body", PKG_FILE_DOWNLOAD_CONNECT_TIMEOUT) !== true) {
|
|
1514 | 1520 |
$static_output .= "failed.\n"; |
1515 | 1521 |
@unlink($prefix . $filename); |
1516 | 1522 |
update_output_window($static_output); |
Also available in: Unified diff
Pkg install error handling and connect timeout RELENG_2_2
Fixes Redmine #4884
1) Line 778-780 - If the fetch of any of the package additional files
fails then bail out. This prevents half-installed packages that look
like they had a successful install.
2) Line 1458 - use the return boolean value from
download_file_with_progress_bar() to determine success or failure here,
like is done in the other places in this file. I had a case of
installing a package with an error (timeout) and the download (I presume
it was the download code) had left an empty file
/usr/local/pkg/autoconfigbackup.xml - it passed the file_exists() check
and the rest of the code went on to happily install the "nothing" in the
package and then claim the package was successfully installed :(
After the above 2 changes I could get reliable indication of
success/failure of the package install and the code would abort nicely
if a download went wrong.
3) Package installs happen either:
i) On the end of a boot after upgrade or config restore, or;
ii) Online while the main system is running (happily)
Therefore there is no need to rush to abort if the download of a package
file is taking some time to get started. It seems better to me to wait a
decent amount of time rather than abort.
Thus I have increased the connect timeout for this from the default (5)
to 30 seconds.
This makes my crap sites load packages much better :)