Merge branch 'remove-stale-sig' into 'master'

Remove stale signature files.

See merge request pacman/pacman!184
This commit is contained in:
Patrick Northon 2025-05-14 11:38:33 +00:00
commit d4434e3156
3 changed files with 35 additions and 13 deletions

View file

@ -610,7 +610,7 @@ static int curl_check_finished_download(alpm_handle_t *handle, CURLM *curlm, CUR
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &timecond);
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
/* Let's check if client requested downloading accompanion *.sig file */
/* Let's check if client requested downloading a companion *.sig file */
if(!payload->signature && payload->download_signature && curlerr == CURLE_OK && payload->respcode < 400) {
struct dload_payload *sig = NULL;
char *url = payload->fileurl;
@ -1098,6 +1098,25 @@ static int move_file(const char *filepath, const char *directory)
return 0;
}
static int unlink_and_maybe_move_file(const char *filepath, const char *directory, const bool do_move)
{
ASSERT(filepath != NULL, return -1);
ASSERT(directory != NULL, return -1);
int ret = finalize_download_file(filepath);
if(ret != 0) {
return ret;
}
const char *filename = mbasename(filepath);
char *dest = _alpm_get_fullpath(directory, filename, "");
unlink(dest);
if(do_move && rename(filepath, dest)) {
FREE(dest);
return -1;
}
FREE(dest);
return 0;
}
static int finalize_download_locations(alpm_list_t *payloads, const char *localpath)
{
ASSERT(payloads != NULL, return -1);
@ -1121,15 +1140,18 @@ static int finalize_download_locations(alpm_list_t *payloads, const char *localp
}
}
if (payload->download_signature) {
const char sig_suffix[] = ".sig";
char *sig_filename = NULL;
size_t sig_filename_len = strlen(payload->destfile_name) + sizeof(sig_suffix);
MALLOC(sig_filename, sig_filename_len, continue);
snprintf(sig_filename, sig_filename_len, "%s%s", payload->destfile_name, sig_suffix);
move_file(sig_filename, localpath);
FREE(sig_filename);
if(unlink_and_maybe_move_file(sig_filename, localpath, payload->download_signature) == -1 &&
payload->download_signature && !payload->signature_optional) {
returnvalue = -1;
}
FREE(sig_filename);
}
}
return returnvalue;

View file

@ -51,7 +51,7 @@ struct dload_payload {
int allow_resume;
int errors_ok;
int unlink_on_fail;
int download_signature; /* specifies if an accompanion *.sig file need to be downloaded*/
int download_signature; /* specifies if a companion *.sig file need to be downloaded*/
int signature_optional; /* *.sig file is optional */
#ifdef HAVE_LIBCURL
CURL *curl;

View file

@ -744,9 +744,9 @@ static int find_dl_candidates(alpm_handle_t *handle, alpm_list_t **files)
ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
need_download = spkg->download_size != 0 || !_alpm_filecache_exists(handle, spkg->filename);
/* even if the package file in the cache we need to check for
* accompanion *.sig file as well.
* If *.sig is not cached then force download the package + its signature file.
/* even if the package file is in the cache, we need to check for
* a companion *.sig file as well.
* If *.sig is not cached, then force download the package + its signature file.
*/
if(!need_download && (siglevel & ALPM_SIG_PACKAGE)) {
char *sig_filename = NULL;