summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Jonglez2020-08-24 23:00:31 +0000
committerBaptiste Jonglez2021-01-31 09:56:16 +0000
commit14d6480e45e5776e4c2761a00540f593a35c684b (patch)
treed3a58a1343b353f2fbdc240a989ae6299f8b827d
parent456efacff7152f06fe8b9776746983c5b8038a0c (diff)
downloadopkg-lede-14d6480e45e5776e4c2761a00540f593a35c684b.tar.gz
download: purge cached packages that have incorrect checksum
Before using a package from the cache, verify its size and checksum against a package index, and delete the package from the cache if they don't match. The install process will then proceed to download the "fixed" package as usual. This allows to cope with remote packages that are rebuilt while keeping the same version number as packages in the local cache. With this change, any outdated package in the local cache will be purged and the new version will be downloaded instead. This is mostly useful when running opkg on the host (e.g. in the imagebuilder). When running on a device, no cache is configured by default, so this change does nothing in that case. Fixes: FS#2690 Signed-off-by: Baptiste Jonglez <git@bitsofnetworks.org> (cherry picked from commit f73d42f0e951e71eae12ecac29b75b05ac543f5e)
-rw-r--r--libopkg/opkg_download.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
index 175282c..3b79856 100644
--- a/libopkg/opkg_download.c
+++ b/libopkg/opkg_download.c
@@ -263,6 +263,8 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir)
char *stripped_filename;
char *urlencoded_path;
char *filename;
+ char *cache_name;
+ char *cache_location;
if (pkg->src == NULL) {
opkg_msg(ERROR,
@@ -296,6 +298,23 @@ int opkg_download_pkg(pkg_t * pkg, const char *dir)
sprintf_alloc(&local_filename, "%s/%s", dir, stripped_filename);
pkg_set_string(pkg, PKG_LOCAL_FILENAME, local_filename);
+ /* Invalidate/remove cached package if it has an incorrect checksum. */
+ if (conf->cache) {
+ cache_name = get_cache_filename(local_filename);
+ sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name);
+ free(cache_name);
+ if (file_exists(cache_location)) {
+ err = opkg_verify_integrity(pkg, cache_location);
+ if (err) {
+ opkg_msg(NOTICE,
+ "Removing %s from cache because it has incorrect checksum.\n",
+ pkg->name);
+ unlink(cache_location);
+ }
+ }
+ free(cache_location);
+ }
+
err = opkg_download_cache(url, local_filename);
free(url);