From 9a3325a56db87cc8c6336225162daefcd190208f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 23 Mar 2011 22:56:54 -0500 Subject: Refactor signature loading code into common function We can use this for both standalone package signatures as well as standalone database signatures. Signed-off-by: Dan McGee --- lib/libalpm/be_package.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'lib/libalpm/be_package.c') diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index e8d26aa7..e86bffe6 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -254,6 +254,7 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full) /* attempt to stat the package file, ensure it exists */ if(stat(pkgfile, &st) == 0) { char *pgpfile; + int ret; newpkg = _alpm_pkg_new(); if(newpkg == NULL) { @@ -265,35 +266,8 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full) /* look around for a PGP signature file; load if available */ MALLOC(pgpfile, strlen(pkgfile) + 5, RET_ERR(PM_ERR_MEMORY, NULL)); sprintf(pgpfile, "%s.sig", pkgfile); - if(access(pgpfile, R_OK) == 0) { - FILE *f; - long bytes; - size_t bytes_read; - f = fopen(pgpfile, "rb"); - fseek(f, 0L, SEEK_END); - bytes = ftell(f); - fseek(f, 0L, SEEK_SET); - /* don't read the file in if it is obviously not the size of a sig */ - if(bytes == 72) { - CALLOC(newpkg->pgpsig.rawdata, bytes, sizeof(char), - RET_ERR(PM_ERR_MEMORY, NULL)); - bytes_read = fread(newpkg->pgpsig.rawdata, sizeof(char), bytes, f); - if(bytes_read == (size_t)bytes) { - newpkg->pgpsig.rawlen = bytes; - _alpm_log(PM_LOG_DEBUG, - "loaded package .sig file, location %s\n", pgpfile); - } else { - _alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file for %s"), - pkgfile); - } - } else { - _alpm_log(PM_LOG_WARNING, _("PGP signature file for %s was abnormal" - " (had length %ld), skipping\n"), pkgfile, bytes); - } - fclose(f); - } else { - _alpm_log(PM_LOG_DEBUG, "no package signature file found\n"); - } + /* TODO: do something with ret value */ + ret = _alpm_load_signature(pgpfile, &(newpkg->pgpsig)); FREE(pgpfile); } else { /* couldn't stat the pkgfile, return an error */ -- cgit v1.2.3-24-g4f1b