[PATCH] alpm: return -1 for error in find_dl_candidates
This is the error value generally used and the calling function explicitly checks for -1, later causing the error to be missed and the transaction to continue.
pacman -S xterm warning: xterm-369-1 is up to date -- reinstalling resolving dependencies... looking for conflicting packages...
Package (1) Old Version New Version Net Change Download Size extra/xterm 369-1 369-1 0.00 MiB 0.42 MiB Total Download Size: 0.42 MiB Total Installed Size: 1.05 MiB Net Upgrade Size: 0.00 MiB :: Proceed with installation? [Y/n] error: no servers configured for repository: extra (1/1) checking keys in keyring [--------------------------------------------------------] 100% (1/1) checking package integrity [--------------------------------------------------------] 100% error: failed to commit transaction (wrong or NULL argument passed) Errors occurred, no packages were upgraded. --- lib/libalpm/sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 36ad6242..acca375e 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -732,7 +732,7 @@ static int find_dl_candidates(alpm_handle_t *handle, alpm_list_t **files) handle->pm_errno = ALPM_ERR_SERVER_NONE; _alpm_log(handle, ALPM_LOG_ERROR, "%s: %s\n", alpm_strerror(handle->pm_errno), repo->treename); - return 1; + return -1; } ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1)); -- 2.33.0
On 10/04/21 at 08:09pm, morganamilo wrote:
This is the error value generally used and the calling function explicitly checks for -1, later causing the error to be missed and the transaction to continue.
This result is not compared to -1, the result of download_files is. If we want to guarantee that download_files will return -1 on error, that's where the return should be normalized, not in find_dl_candidates. Tying the API of one function to another like this is just going to cause confusion and breakage when somebody forgets in the future. Really, the caller of download_files should just check for a successful return; we return 1 as an error from lots of functions.
participants (2)
-
Andrew Gregory
-
morganamilo