[pacman-dev] [PATCH] alpm_db_update: indicate if dbs were up to date
Andrew Gregory
andrew.gregory.8 at gmail.com
Tue Apr 27 04:02:15 UTC 2021
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 at gmail.com>
---
Please include this for v6.0. Pacutils uses the up-to-date indicator.
lib/libalpm/alpm.h | 3 ++-
lib/libalpm/dload.c | 35 +++++++++++++++++++++--------------
lib/libalpm/sync.c | 2 +-
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 2e99d4d8..f47ddc1d 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1356,7 +1356,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 57d25383..00a729ec 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -788,6 +788,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)
@@ -795,6 +799,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) {
@@ -846,6 +851,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);
@@ -854,11 +861,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)
@@ -871,20 +882,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(payload->fileurl, localpath, payload->force) != -1) {
- success = 1;
- }
+ ret = handle->fetchcb(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));
@@ -892,18 +901,16 @@ int _alpm_download(alpm_handle_t *handle,
ret = handle->fetchcb(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"));
--
2.31.1
More information about the pacman-dev
mailing list