Checks if the signature already exists in cache before attempting the
download. Previously, every call to 'opkg upgrade' would download the
signature. This led to problems in the following scenario:
* Call 'opkg --download-only upgrade' to download any package upgrades.
* Disconnect the package repository (i.e. disconnect removable media)
* Call 'opkg upgrade'
Previously 'opkg upgrade' would fail because it could not download the
signature files.
Adds function for removing the signature file. The signature file
should be removed if the verification fails.
Signed-off-by: Bryan Evenson <
evenso...@gmail.com>
---
libopkg/opkg_download.c | 40 +++++++++++++++++++++++++++++++++++++++-
libopkg/opkg_download.h | 1 +
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
index 5c74f66..e83aeda 100644
--- a/libopkg/opkg_download.c
+++ b/libopkg/opkg_download.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <unistd.h>
#include <libgen.h>
+#include <sys/stat.h>
#include "opkg_download.h"
#include "opkg_message.h"
@@ -248,12 +249,45 @@ static char *get_pkg_url(pkg_t * pkg)
return url;
}
+void pkg_remove_signature(pkg_t * pkg)
+{
+ char *pkg_url;
+ char *sig_url;
+ char *sig_ext;
+ char *sig_file;
+
+ pkg_url = get_pkg_url(pkg);
+ if (pkg_url) {
+
+ if (strcmp(opkg_config->signature_type, "gpg-asc") == 0)
+ sig_ext = "asc";
+ else
+ sig_ext = "sig";
+
+ sprintf_alloc(&sig_url, "%s.%s", pkg_url, sig_ext);
+ free(pkg_url);
+
+ sig_file = get_cache_location(sig_url);
+ unlink(sig_file);
+ free(sig_file);
+ free(sig_url);
+ }
+}
+
+/** \brief pkg_download_signature: download a package signature
+ * \details First checks if the signature has already been downloaded
+ *
+ * \param pkg the package associated with the signature
+ * \return The signature filename if success, NULL if error occurs
+ *
+ */
char *pkg_download_signature(pkg_t * pkg)
{
char *pkg_url;
char *sig_url;
char *sig_ext;
char *sig_file;
+ struct stat sig_stat;
pkg_url = get_pkg_url(pkg);
if (!pkg_url)
@@ -267,7 +301,11 @@ char *pkg_download_signature(pkg_t * pkg)
sprintf_alloc(&sig_url, "%s.%s", pkg_url, sig_ext);
free(pkg_url);
- sig_file = opkg_download_cache(sig_url, NULL, NULL);
+ sig_file = get_cache_location(sig_url);
+ if (stat(sig_file, &sig_stat)) {
+ free(sig_file);
+ sig_file = opkg_download_cache(sig_url, NULL, NULL);
+ }
free(sig_url);
return sig_file;
diff --git a/libopkg/opkg_download.h b/libopkg/opkg_download.h
index e88af85..c131232 100644
--- a/libopkg/opkg_download.h
+++ b/libopkg/opkg_download.h
@@ -36,6 +36,7 @@ int opkg_download(const char *src, const char *dest_file_name,
char *opkg_download_cache(const char *src, curl_progress_func cb, void *data);
int opkg_download_pkg(pkg_t * pkg);
int opkg_download_pkg_to_dir(pkg_t * pkg, const char *dir);
+void pkg_remove_signature(pkg_t * pkg);
char *pkg_download_signature(pkg_t * pkg);
/*
--
2.17.1