summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2021-04-27 05:47:58 +0200
committerAllan McRae <allan@archlinux.org>2021-05-01 04:08:14 +0200
commiteb1a63a516cb3791d0084b0d05b074c963aa01e9 (patch)
tree7532ab9d524b90d4c83713f68197092f8048014f
parent0ff94ae85d40efdc177e1852ef58848f82d14156 (diff)
downloadpacman-eb1a63a516cb3791d0084b0d05b074c963aa01e9.tar.gz
pacman-eb1a63a516cb3791d0084b0d05b074c963aa01e9.tar.xz
alpm_db_update: indicate if dbs were up to date
Restore the prior indicator whether or not databases were up to date. 0 is used to indicate if *any* db was actually updated as callers are more likely to care about that than if *all* dbs were updated. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/dload.c35
-rw-r--r--lib/libalpm/sync.c2
3 files changed, 24 insertions, 16 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 65b8e2fb..101d686b 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1361,7 +1361,8 @@ int alpm_db_remove_server(alpm_db_t *db, const char *url);
* @param dbs list of package databases to update
* @param force if true, then forces the update, otherwise update only in case
* the databases aren't up to date
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ * @return 0 on success, -1 on error (pm_errno is set accordingly),
+ * 1 if all databases are up to to date
*/
int alpm_db_update(alpm_handle_t *handle, alpm_list_t *dbs, int force);
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 9ed1a02a..935f5418 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -789,6 +789,10 @@ cleanup:
return ret;
}
+/* Returns -1 if an error happened for a required file
+ * Returns 0 if a payload was actually downloaded
+ * Returns 1 if no files were downloaded and all errors were non-fatal
+ */
static int curl_download_internal(alpm_handle_t *handle,
alpm_list_t *payloads /* struct dload_payload */,
const char *localpath)
@@ -796,6 +800,7 @@ static int curl_download_internal(alpm_handle_t *handle,
int active_downloads_num = 0;
int err = 0;
int max_streams = handle->parallel_downloads;
+ int updated = 0; /* was a file actually updated */
CURLM *curlm = handle->curlm;
while(active_downloads_num > 0 || payloads) {
@@ -847,6 +852,8 @@ static int curl_download_internal(alpm_handle_t *handle,
*/
payloads = NULL;
err = -1;
+ } else if(ret == 0) {
+ updated = 1;
}
} else {
_alpm_log(handle, ALPM_LOG_ERROR, _("curl transfer error: %d\n"), msg->msg);
@@ -855,11 +862,15 @@ static int curl_download_internal(alpm_handle_t *handle,
}
_alpm_log(handle, ALPM_LOG_DEBUG, "curl_download_internal return code is %d\n", err);
- return err;
+ return err ? -1 : updated ? 0 : 1;
}
#endif
+/* Returns -1 if an error happened for a required file
+ * Returns 0 if a payload was actually downloaded
+ * Returns 1 if no files were downloaded and all errors were non-fatal
+ */
int _alpm_download(alpm_handle_t *handle,
alpm_list_t *payloads /* struct dload_payload */,
const char *localpath)
@@ -872,20 +883,18 @@ int _alpm_download(alpm_handle_t *handle,
#endif
} else {
alpm_list_t *p;
+ int updated = 0;
for(p = payloads; p; p = p->next) {
struct dload_payload *payload = p->data;
alpm_list_t *s;
- int success = 0;
+ int ret = -1;
if(payload->fileurl) {
- if (handle->fetchcb(handle->fetchcb_ctx, payload->fileurl, localpath, payload->force) != -1) {
- success = 1;
- }
+ ret = handle->fetchcb(handle->fetchcb_ctx, payload->fileurl, localpath, payload->force);
} else {
- for(s = payload->servers; s; s = s->next) {
+ for(s = payload->servers; s && ret == -1; s = s->next) {
const char *server = s->data;
char *fileurl;
- int ret;
size_t len = strlen(server) + strlen(payload->filepath) + 2;
MALLOC(fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
@@ -893,18 +902,16 @@ int _alpm_download(alpm_handle_t *handle,
ret = handle->fetchcb(handle->fetchcb_ctx, fileurl, localpath, payload->force);
free(fileurl);
-
- if (ret != -1) {
- success = 1;
- break;
- }
}
}
- if(!success && !payload->errors_ok) {
+
+ if(ret == -1 && !payload->errors_ok) {
RET_ERR(handle, ALPM_ERR_EXTERNAL_DOWNLOAD, -1);
+ } else if(ret == 0) {
+ updated = 1;
}
}
- return 0;
+ return updated ? 0 : 1;
}
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 7fa50a13..2419cc69 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -815,7 +815,7 @@ static int download_files(alpm_handle_t *handle)
}
ret = _alpm_download(handle, payloads, cachedir);
- if(ret != 0) {
+ if(ret == -1) {
event.type = ALPM_EVENT_PKG_RETRIEVE_FAILED;
EVENT(handle, &event);
_alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n"));