Refactor some args out of pkg_load_internal
Just pass the entire sync package in if we have it; that way we can do any necessary operations involving it rather than have a parameter list growing endlessly. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
c7e4005e5c
commit
dc3336c277
3 changed files with 37 additions and 37 deletions
|
@ -276,19 +276,17 @@ static alpm_file_t *files_msort(alpm_file_t *files, size_t n)
|
||||||
* Load a package and create the corresponding alpm_pkg_t struct.
|
* Load a package and create the corresponding alpm_pkg_t struct.
|
||||||
* @param handle the context handle
|
* @param handle the context handle
|
||||||
* @param pkgfile path to the package file
|
* @param pkgfile path to the package file
|
||||||
|
* @param syncpkg package object to load verification data from (md5sum,
|
||||||
|
* sha256sum, and/or base64 signature)
|
||||||
* @param full whether to stop the load after metadata is read or continue
|
* @param full whether to stop the load after metadata is read or continue
|
||||||
* through the full archive
|
* through the full archive
|
||||||
* @param md5sum the expected md5sum of the package file if known
|
|
||||||
* @param sha256sum the expected sha256sum of the package file if known
|
|
||||||
* @param base64_sig the encoded signature of the package file if known
|
|
||||||
* @param level the required level of signature verification
|
* @param level the required level of signature verification
|
||||||
* @return An information filled alpm_pkg_t struct
|
* @return An information filled alpm_pkg_t struct
|
||||||
*/
|
*/
|
||||||
alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile,
|
alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile,
|
||||||
int full, const char *md5sum, const char *sha256sum, const char *base64_sig,
|
alpm_pkg_t *syncpkg, int full, alpm_siglevel_t level)
|
||||||
alpm_siglevel_t level)
|
|
||||||
{
|
{
|
||||||
int ret, skip_checksums, config = 0;
|
int ret, use_sig, config = 0;
|
||||||
struct archive *archive;
|
struct archive *archive;
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
alpm_pkg_t *newpkg = NULL;
|
alpm_pkg_t *newpkg = NULL;
|
||||||
|
@ -314,46 +312,50 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* can we get away with skipping checksums? */
|
/* can we get away with skipping checksums? */
|
||||||
skip_checksums = 0;
|
use_sig = 0;
|
||||||
if(level & ALPM_SIG_PACKAGE) {
|
if(level & ALPM_SIG_PACKAGE) {
|
||||||
if(base64_sig) {
|
if(syncpkg && syncpkg->base64_sig) {
|
||||||
skip_checksums = 1;
|
use_sig = 1;
|
||||||
} else {
|
} else {
|
||||||
char *sigpath = _alpm_sigpath(handle, pkgfile);
|
char *sigpath = _alpm_sigpath(handle, pkgfile);
|
||||||
if(sigpath && !_alpm_access(handle, NULL, sigpath, R_OK)) {
|
if(sigpath && !_alpm_access(handle, NULL, sigpath, R_OK)) {
|
||||||
skip_checksums = 1;
|
use_sig = 1;
|
||||||
}
|
}
|
||||||
free(sigpath);
|
free(sigpath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "md5sum: %s\n", md5sum);
|
if(syncpkg && !use_sig) {
|
||||||
if(!skip_checksums && md5sum && !sha256sum) {
|
if(syncpkg->md5sum && !syncpkg->sha256sum) {
|
||||||
|
_alpm_log(handle, ALPM_LOG_DEBUG, "md5sum: %s\n", syncpkg->md5sum);
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
|
||||||
if(_alpm_test_checksum(pkgfile, md5sum, ALPM_CSUM_MD5) != 0) {
|
if(_alpm_test_checksum(pkgfile, syncpkg->md5sum, ALPM_CSUM_MD5) != 0) {
|
||||||
alpm_pkg_free(newpkg);
|
alpm_pkg_free(newpkg);
|
||||||
RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL);
|
RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "sha256sum: %s\n", sha256sum);
|
if(syncpkg->sha256sum) {
|
||||||
if(!skip_checksums && sha256sum) {
|
_alpm_log(handle, ALPM_LOG_DEBUG, "sha256sum: %s\n", syncpkg->sha256sum);
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "checking sha256sum for %s\n", pkgfile);
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking sha256sum for %s\n", pkgfile);
|
||||||
if(_alpm_test_checksum(pkgfile, sha256sum, ALPM_CSUM_SHA256) != 0) {
|
if(_alpm_test_checksum(pkgfile, syncpkg->sha256sum, ALPM_CSUM_SHA256) != 0) {
|
||||||
alpm_pkg_free(newpkg);
|
alpm_pkg_free(newpkg);
|
||||||
RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL);
|
RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "base64_sig: %s\n", base64_sig);
|
if(use_sig) {
|
||||||
if(level & ALPM_SIG_PACKAGE &&
|
const char *sig = syncpkg ? syncpkg->base64_sig : NULL;
|
||||||
_alpm_check_pgp_helper(handle, pkgfile, base64_sig,
|
_alpm_log(handle, ALPM_LOG_DEBUG, "sig data: %s\n", sig ? sig : "<from .sig>");
|
||||||
|
if(_alpm_check_pgp_helper(handle, pkgfile, sig,
|
||||||
level & ALPM_SIG_PACKAGE_OPTIONAL, level & ALPM_SIG_PACKAGE_MARGINAL_OK,
|
level & ALPM_SIG_PACKAGE_OPTIONAL, level & ALPM_SIG_PACKAGE_MARGINAL_OK,
|
||||||
level & ALPM_SIG_PACKAGE_UNKNOWN_OK)) {
|
level & ALPM_SIG_PACKAGE_UNKNOWN_OK)) {
|
||||||
handle->pm_errno = ALPM_ERR_PKG_INVALID_SIG;
|
handle->pm_errno = ALPM_ERR_PKG_INVALID_SIG;
|
||||||
_alpm_pkg_free(newpkg);
|
_alpm_pkg_free(newpkg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* next- try to create an archive object to read in the package */
|
/* next- try to create an archive object to read in the package */
|
||||||
if((archive = archive_read_new()) == NULL) {
|
if((archive = archive_read_new()) == NULL) {
|
||||||
|
@ -487,7 +489,7 @@ int SYMEXPORT alpm_pkg_load(alpm_handle_t *handle, const char *filename, int ful
|
||||||
CHECK_HANDLE(handle, return -1);
|
CHECK_HANDLE(handle, return -1);
|
||||||
ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
ASSERT(pkg != NULL, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
|
||||||
|
|
||||||
*pkg = _alpm_pkg_load_internal(handle, filename, full, NULL, NULL, NULL, level);
|
*pkg = _alpm_pkg_load_internal(handle, filename, NULL, full, level);
|
||||||
if(*pkg == NULL) {
|
if(*pkg == NULL) {
|
||||||
/* pm_errno is set by pkg_load */
|
/* pm_errno is set by pkg_load */
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -150,8 +150,7 @@ void _alpm_pkg_free_trans(alpm_pkg_t *pkg);
|
||||||
|
|
||||||
|
|
||||||
alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile,
|
alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile,
|
||||||
int full, const char *md5sum, const char *sha256sum, const char *base64_sig,
|
alpm_pkg_t *syncpkg, int full, alpm_siglevel_t level);
|
||||||
alpm_siglevel_t level);
|
|
||||||
|
|
||||||
int _alpm_pkg_cmp(const void *p1, const void *p2);
|
int _alpm_pkg_cmp(const void *p1, const void *p2);
|
||||||
int _alpm_pkg_compare_versions(alpm_pkg_t *local_pkg, alpm_pkg_t *pkg);
|
int _alpm_pkg_compare_versions(alpm_pkg_t *local_pkg, alpm_pkg_t *pkg);
|
||||||
|
|
|
@ -938,8 +938,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG,
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
||||||
"replacing pkgcache entry with package file for target %s\n",
|
"replacing pkgcache entry with package file for target %s\n",
|
||||||
spkg->name);
|
spkg->name);
|
||||||
alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1, spkg->md5sum,
|
alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, spkg, 1, level);
|
||||||
spkg->sha256sum, spkg->base64_sig, level);
|
|
||||||
if(!pkgfile) {
|
if(!pkgfile) {
|
||||||
prompt_to_delete(trans, filepath, handle->pm_errno);
|
prompt_to_delete(trans, filepath, handle->pm_errno);
|
||||||
errors++;
|
errors++;
|
||||||
|
|
Loading…
Add table
Reference in a new issue