mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
improve download_internal error messages
download_internal is supposed to always set pm_errno but did not in many
cases.
The most important (and tested) change is the one concerning fetchStat. This
is typically where the code will fail when the network is down for example.
Before commit d2dbb04a9a
, this fetchStat call did not exist and the
same kind of errors would be encountered in the fetchXGet call that follows.
I just copied the error printing to restore the old behavior.
Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
b8b8c78627
commit
a2c9cbdbdc
@ -118,13 +118,14 @@ static int download_internal(const char *url, const char *localpath,
|
|||||||
|
|
||||||
filename = get_filename(url);
|
filename = get_filename(url);
|
||||||
if(!filename) {
|
if(!filename) {
|
||||||
return(-1);
|
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
|
||||||
|
RET_ERR(PM_ERR_SERVER_BAD_URL, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileurl = fetchParseURL(url);
|
fileurl = fetchParseURL(url);
|
||||||
if(!fileurl) {
|
if(!fileurl) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
|
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
|
||||||
RET_ERR(PM_ERR_SERVER_BAD_URL, -1);
|
RET_ERR(PM_ERR_LIBFETCH, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
destfile = get_destfile(localpath, filename);
|
destfile = get_destfile(localpath, filename);
|
||||||
@ -179,6 +180,9 @@ static int download_internal(const char *url, const char *localpath,
|
|||||||
* non-stat request, so avoid it. */
|
* non-stat request, so avoid it. */
|
||||||
fetchLastErrCode = 0;
|
fetchLastErrCode = 0;
|
||||||
if(fetchStat(fileurl, &ust, "") == -1) {
|
if(fetchStat(fileurl, &ust, "") == -1) {
|
||||||
|
pm_errno = PM_ERR_LIBFETCH;
|
||||||
|
_alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"),
|
||||||
|
filename, gethost(fileurl), fetchLastErrString);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -230,6 +234,7 @@ static int download_internal(const char *url, const char *localpath,
|
|||||||
dl_thisfile = 0;
|
dl_thisfile = 0;
|
||||||
localf = fopen(tempfile, "wb");
|
localf = fopen(tempfile, "wb");
|
||||||
if(localf == NULL) { /* still null? */
|
if(localf == NULL) { /* still null? */
|
||||||
|
pm_errno = PM_ERR_RETRIEVE;
|
||||||
_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
|
_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
|
||||||
tempfile, strerror(errno));
|
tempfile, strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -247,6 +252,7 @@ static int download_internal(const char *url, const char *localpath,
|
|||||||
size_t nwritten = 0;
|
size_t nwritten = 0;
|
||||||
nwritten = fwrite(buffer, 1, nread, localf);
|
nwritten = fwrite(buffer, 1, nread, localf);
|
||||||
if((nwritten != nread) || ferror(localf)) {
|
if((nwritten != nread) || ferror(localf)) {
|
||||||
|
pm_errno = PM_ERR_RETRIEVE;
|
||||||
_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
|
_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
|
||||||
tempfile, strerror(errno));
|
tempfile, strerror(errno));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user