summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm.h1
-rw-r--r--lib/libalpm/be_package.c2
-rw-r--r--lib/libalpm/error.c2
-rw-r--r--lib/libalpm/sync.c32
4 files changed, 20 insertions, 17 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a91b00f0..8a95f26a 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1093,6 +1093,7 @@ enum _alpm_errno_t {
ALPM_ERR_PKG_NOT_FOUND,
ALPM_ERR_PKG_IGNORED,
ALPM_ERR_PKG_INVALID,
+ ALPM_ERR_PKG_INVALID_CHECKSUM,
ALPM_ERR_PKG_INVALID_SIG,
ALPM_ERR_PKG_OPEN,
ALPM_ERR_PKG_CANT_REMOVE,
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index f80790cd..41b1eb2d 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -313,7 +313,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, const char *pkgfile,
_alpm_log(handle, ALPM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
if(_alpm_test_md5sum(pkgfile, md5sum) != 0) {
alpm_pkg_free(newpkg);
- RET_ERR(handle, ALPM_ERR_PKG_INVALID, NULL);
+ RET_ERR(handle, ALPM_ERR_PKG_INVALID_CHECKSUM, NULL);
}
}
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 7e0e5c85..b3f56819 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -108,6 +108,8 @@ const char SYMEXPORT *alpm_strerror(enum _alpm_errno_t err)
case ALPM_ERR_PKG_IGNORED:
return _("operation cancelled due to ignorepkg");
case ALPM_ERR_PKG_INVALID:
+ return _("invalid or corrupted package");
+ case ALPM_ERR_PKG_INVALID_CHECKSUM:
return _("invalid or corrupted package (checksum)");
case ALPM_ERR_PKG_INVALID_SIG:
return _("invalid or corrupted package (PGP signature)");
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index ca7e6579..663fca6c 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -677,24 +677,18 @@ static int apply_deltas(alpm_handle_t *handle)
*
* @param trans the transaction
* @param filename the absolute path of the file to test
- * @param md5sum the expected md5sum of the file
*
- * @return 0 if the md5sum matched, 1 if not, -1 in case of errors
+ * @return 1 if file was removed, 0 otherwise
*/
-static int test_md5sum(alpm_trans_t *trans, const char *filepath,
- const char *md5sum)
+static int prompt_to_delete(alpm_trans_t *trans, const char *filepath)
{
- int ret = _alpm_test_md5sum(filepath, md5sum);
- if(ret == 1) {
- int doremove = 0;
- QUESTION(trans, ALPM_TRANS_CONV_CORRUPTED_PKG, (char *)filepath,
- NULL, NULL, &doremove);
- if(doremove) {
- unlink(filepath);
- }
+ int doremove = 0;
+ QUESTION(trans, ALPM_TRANS_CONV_CORRUPTED_PKG, (char *)filepath,
+ NULL, NULL, &doremove);
+ if(doremove) {
+ unlink(filepath);
}
-
- return ret;
+ return doremove;
}
static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas,
@@ -715,7 +709,9 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas,
alpm_delta_t *d = alpm_list_getdata(i);
char *filepath = _alpm_filecache_find(handle, d->delta);
- if(test_md5sum(trans, filepath, d->delta_md5) != 0) {
+ ret = _alpm_test_md5sum(filepath, d->delta_md5);
+ if(ret != 0) {
+ prompt_to_delete(trans, filepath);
errors++;
*data = alpm_list_add(*data, strdup(d->delta));
}
@@ -903,6 +899,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1, spkg->md5sum,
spkg->base64_sig, level);
if(!pkgfile) {
+ prompt_to_delete(trans, filepath);
errors++;
*data = alpm_list_add(*data, strdup(filename));
FREE(filepath);
@@ -920,7 +917,10 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
if(errors) {
- RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1);
+ if(!handle->pm_errno) {
+ RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1);
+ }
+ return -1;
}
if(trans->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) {