summaryrefslogtreecommitdiffstats
path: root/patches
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-06 13:01:53 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-06 13:01:53 (EDT)
commit1abd6fb68307e9f09864bc428fb79c23427bf5c2 (patch)
tree9d9fe81bbfe537428669b0257549d2576585c358 /patches
parent0c8c7e865dd4be7e6e32182211fc0d1c8acdaab9 (diff)
patches: Detect and optionally suffix gzipped lists
Diffstat (limited to 'patches')
-rw-r--r--patches/0005-libopkg-Detect-gzipped-pkg-lists-by-magic-number.patch81
-rw-r--r--patches/0006-libopkg-Add-optional-suffix-to-list-files.patch63
2 files changed, 144 insertions, 0 deletions
diff --git a/patches/0005-libopkg-Detect-gzipped-pkg-lists-by-magic-number.patch b/patches/0005-libopkg-Detect-gzipped-pkg-lists-by-magic-number.patch
new file mode 100644
index 0000000..98a6cfb
--- /dev/null
+++ b/patches/0005-libopkg-Detect-gzipped-pkg-lists-by-magic-number.patch
@@ -0,0 +1,81 @@
+From e87ff77171376dca31941cacac97db7458fedc93 Mon Sep 17 00:00:00 2001
+From: Patrick McDermott <patrick.mcdermott@libiquity.com>
+Date: Sat, 6 Apr 2019 12:40:05 -0400
+Subject: [PATCH 5/6] libopkg: Detect gzipped pkg lists by magic number
+
+Signed-off-by: Patrick McDermott <patrick.mcdermott@libiquity.com>
+---
+ libbb/gzip.h | 2 ++
+ libopkg/pkg_hash.c | 27 ++++++++++++++++++++-------
+ 2 files changed, 22 insertions(+), 7 deletions(-)
+
+diff --git a/libbb/gzip.h b/libbb/gzip.h
+index 3a61a1d..28e3a50 100644
+--- a/libbb/gzip.h
++++ b/libbb/gzip.h
+@@ -22,6 +22,8 @@
+ #include <signal.h>
+ #include <pthread.h>
+
++#define GZIP_MAGIC "\037\213" /* gzip magic number, 1F 8B */
++
+ struct gzip_handle {
+ FILE *file;
+ struct gzip_handle *gzip;
+diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c
+index 611f3b9..b536db7 100644
+--- a/libopkg/pkg_hash.c
++++ b/libopkg/pkg_hash.c
+@@ -99,21 +99,34 @@ pkg_hash_add_from_file(const char *file_name,
+ {
+ pkg_t *pkg;
+ FILE *fp;
++ char magic[2];
++ int is_gzip = 0;
+ char *buf;
+ const size_t len = 4096;
+ int ret = 0;
+ struct gzip_handle zh;
+
+- if (src && src->gzip) {
+- fp = gzip_fdopen(&zh, file_name);
+- } else {
+- fp = fopen(file_name, "r");
+- }
+-
++ fp = fopen(file_name, "r");
+ if (fp == NULL) {
+ opkg_perror(ERROR, "Failed to open %s", file_name);
+ return -1;
+ }
++ if (fread(magic, 1, 2, fp) != 2) {
++ opkg_perror(ERROR, "Failed to read %s", file_name);
++ fclose(fp);
++ return -1;
++ }
++ (void)fseek(fp, 0L, SEEK_SET);
++
++ if (src && src->gzip && memcmp(magic, GZIP_MAGIC, 2) == 0) {
++ fclose(fp);
++ fp = gzip_fdopen(&zh, file_name);
++ if (fp == NULL) {
++ opkg_perror(ERROR, "Failed to open %s", file_name);
++ return -1;
++ }
++ is_gzip = 1;
++ }
+
+ buf = xmalloc(len);
+
+@@ -165,7 +178,7 @@ pkg_hash_add_from_file(const char *file_name,
+ free(buf);
+ fclose(fp);
+
+- if (src && src->gzip)
++ if (is_gzip)
+ gzip_close(&zh);
+
+ return ret;
+--
+2.11.0
+
diff --git a/patches/0006-libopkg-Add-optional-suffix-to-list-files.patch b/patches/0006-libopkg-Add-optional-suffix-to-list-files.patch
new file mode 100644
index 0000000..58c381e
--- /dev/null
+++ b/patches/0006-libopkg-Add-optional-suffix-to-list-files.patch
@@ -0,0 +1,63 @@
+From 653d45cca7aff2ced1abc6fba4e3a71aec842abb Mon Sep 17 00:00:00 2001
+From: Patrick McDermott <patrick.mcdermott@libiquity.com>
+Date: Sat, 6 Apr 2019 12:53:07 -0400
+Subject: [PATCH 6/6] libopkg: Add optional suffix to list files
+
+Signed-off-by: Patrick McDermott <patrick.mcdermott@libiquity.com>
+---
+ CMakeLists.txt | 2 ++
+ libopkg/opkg.c | 3 ++-
+ libopkg/opkg_cmd.c | 3 ++-
+ 3 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index dfb1b81..6bf4da9 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -10,6 +10,7 @@ SET(CONF_FILE "/etc/opkg.conf" CACHE STRING "Override default configuration file
+ SET(LOCK_FILE "/var/lock/opkg.lock" CACHE STRING "Override lock file path")
+ SET(STATE_DIR_PREFIX "/usr/lib" CACHE STRING "Override opkg state directory prefix")
+ SET(PATH_SPEC "/usr/sbin:/usr/bin:/sbin:/bin" CACHE STRING "Override default PATH value")
++SET(LIST_FILES_SUFFIX "" CACHE STRING "Override list files suffix, e.g. .gz")
+ SET(VERSION "" CACHE STRING "Override version")
+
+ OPTION(STATIC_UBOX "Statically link libubox" OFF)
+@@ -47,6 +48,7 @@ ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -Wmissing-declarations
+ -DHOST_CPU_STR="${HOST_CPU}"
+ -DBUILD_CPU=${BUILD_CPU}
+ -DPATH_SPEC="${PATH_SPEC}"
++ -DLIST_FILES_SUFFIX="${LIST_FILES_SUFFIX}"
+ -DVERSION="${VERSION}"
+ )
+
+diff --git a/libopkg/opkg.c b/libopkg/opkg.c
+index aba6364..09de2d6 100644
+--- a/libopkg/opkg.c
++++ b/libopkg/opkg.c
+@@ -537,7 +537,8 @@ opkg_update_package_lists(opkg_progress_callback_t progress_callback,
+ sprintf_alloc(&url, "%s/%s", src->value,
+ src->gzip ? "Packages.gz" : "Packages");
+
+- sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
++ sprintf_alloc(&list_file_name, "%s/%s" LIST_FILES_SUFFIX,
++ lists_dir, src->name);
+
+ if (opkg_download(url, list_file_name, 0)) {
+ opkg_msg(ERROR, "Couldn't retrieve %s\n", url);
+diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
+index 0a4180d..8e04b54 100644
+--- a/libopkg/opkg_cmd.c
++++ b/libopkg/opkg_cmd.c
+@@ -128,7 +128,8 @@ static int opkg_update_cmd(int argc, char **argv)
+ sprintf_alloc(&url, "%s/%s", src->value,
+ src->gzip ? "Packages.gz" : "Packages");
+
+- sprintf_alloc(&list_file_name, "%s/%s", lists_dir, src->name);
++ sprintf_alloc(&list_file_name, "%s/%s" LIST_FILES_SUFFIX,
++ lists_dir, src->name);
+ pkglist_dl_error = 0;
+ if (opkg_download(url, list_file_name, 0)) {
+ failures++;
+--
+2.11.0
+