summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools
diff options
context:
space:
mode:
authorAlejandro del Castillo <alejandro.delcastillo@ni.com>2015-11-13 09:59:15 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-11-25 08:08:16 +0000
commitcdad67c37ac79a362dd31ac6ad92462f5e5d8c66 (patch)
treee0862259a2c3ef04838962f08dfa6b921c8e4c69 /meta/recipes-devtools
parent2ec77de50584b8c4863a1da66a2393bf64acd88e (diff)
downloadpoky-cdad67c37ac79a362dd31ac6ad92462f5e5d8c66.tar.gz
opkg: add cache filename length fixes
(From OE-Core rev: 8e53500a7c05204fc63759f456639545a022e82b) Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools')
-rw-r--r--meta/recipes-devtools/opkg/opkg/0001-string_util-New-file-with-bin_to_hex-function.patch122
-rw-r--r--meta/recipes-devtools/opkg/opkg/0002-md5-Add-md5_to_string-function.patch110
-rw-r--r--meta/recipes-devtools/opkg/opkg/0003-sha256-Add-sha256_to_string-function.patch110
-rw-r--r--meta/recipes-devtools/opkg/opkg/0004-opkg_download-Use-short-cache-file-name.patch85
-rw-r--r--meta/recipes-devtools/opkg/opkg_0.3.0.bb4
5 files changed, 431 insertions, 0 deletions
diff --git a/meta/recipes-devtools/opkg/opkg/0001-string_util-New-file-with-bin_to_hex-function.patch b/meta/recipes-devtools/opkg/opkg/0001-string_util-New-file-with-bin_to_hex-function.patch
new file mode 100644
index 0000000000..fb3ac462df
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/0001-string_util-New-file-with-bin_to_hex-function.patch
@@ -0,0 +1,122 @@
1From 646b80024567a6245c598be3374653fa1fa09a12 Mon Sep 17 00:00:00 2001
2From: Paul Barker <paul@paulbarker.me.uk>
3Date: Sat, 7 Nov 2015 10:23:49 +0000
4Subject: [PATCH 1/4] string_util: New file with bin_to_hex function
5
6This function does very simple conversion from binary data to a hex string.
7
8Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
9Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com>
10
11Upstream-Status: Accepted
12---
13 libopkg/Makefile.am | 4 ++--
14 libopkg/string_util.c | 42 ++++++++++++++++++++++++++++++++++++++++++
15 libopkg/string_util.h | 24 ++++++++++++++++++++++++
16 3 files changed, 68 insertions(+), 2 deletions(-)
17 create mode 100644 libopkg/string_util.c
18 create mode 100644 libopkg/string_util.h
19
20diff --git a/libopkg/Makefile.am b/libopkg/Makefile.am
21index ee3fbee..3e62c24 100644
22--- a/libopkg/Makefile.am
23+++ b/libopkg/Makefile.am
24@@ -13,7 +13,7 @@ opkg_headers = active_list.h cksum_list.h conffile.h conffile_list.h \
25 pkg_depends.h pkg_dest.h pkg_dest_list.h pkg_extract.h pkg_hash.h \
26 pkg_parse.h pkg_src.h pkg_src_list.h pkg_vec.h release.h \
27 release_parse.h sha256.h sprintf_alloc.h str_list.h void_list.h \
28- xregex.h xsystem.h xfuncs.h opkg_verify.h
29+ xregex.h xsystem.h xfuncs.h opkg_verify.h string_util.h
30
31 opkg_sources = opkg_cmd.c opkg_configure.c opkg_download.c \
32 opkg_install.c opkg_remove.c opkg_conf.c release.c \
33@@ -23,7 +23,7 @@ opkg_sources = opkg_cmd.c opkg_configure.c opkg_download.c \
34 pkg_src.c pkg_src_list.c str_list.c void_list.c active_list.c \
35 file_util.c opkg_message.c md5.c parse_util.c cksum_list.c \
36 sprintf_alloc.c xregex.c xsystem.c xfuncs.c opkg_archive.c \
37- opkg_verify.c
38+ opkg_verify.c string_util.c
39
40 if HAVE_CURL
41 opkg_sources += opkg_download_curl.c
42diff --git a/libopkg/string_util.c b/libopkg/string_util.c
43new file mode 100644
44index 0000000..822cab6
45--- /dev/null
46+++ b/libopkg/string_util.c
47@@ -0,0 +1,42 @@
48+/* vi: set expandtab sw=4 sts=4: */
49+/* string_util.c - convenience routines for common string operations
50+
51+ Copyright (C) 2015 Paul Barker
52+
53+ This program is free software; you can redistribute it and/or
54+ modify it under the terms of the GNU General Public License as
55+ published by the Free Software Foundation; either version 2, or (at
56+ your option) any later version.
57+
58+ This program is distributed in the hope that it will be useful, but
59+ WITHOUT ANY WARRANTY; without even the implied warranty of
60+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
61+ General Public License for more details.
62+*/
63+
64+#include "config.h"
65+
66+#include "string_util.h"
67+#include "xfuncs.h"
68+
69+char *bin_to_hex(const void *bin_data, size_t len)
70+{
71+ const unsigned char *src = (const unsigned char *)bin_data;
72+ char *buf = xmalloc(2 * len + 1);
73+ int i;
74+
75+ static const unsigned char bin2hex[16] = {
76+ '0', '1', '2', '3',
77+ '4', '5', '6', '7',
78+ '8', '9', 'a', 'b',
79+ 'c', 'd', 'e', 'f'
80+ };
81+
82+ for (i = 0; i < len; i++) {
83+ buf[i * 2] = bin2hex[src[i] >> 4];
84+ buf[i * 2 + 1] = bin2hex[src[i] & 0xf];
85+ }
86+
87+ buf[len * 2] = '\0';
88+ return buf;
89+}
90diff --git a/libopkg/string_util.h b/libopkg/string_util.h
91new file mode 100644
92index 0000000..a920e2a
93--- /dev/null
94+++ b/libopkg/string_util.h
95@@ -0,0 +1,24 @@
96+/* vi: set expandtab sw=4 sts=4: */
97+/* string_util.h - convenience routines for common file operations
98+
99+ Copyright (C) 2015 Paul Barker
100+
101+ This program is free software; you can redistribute it and/or
102+ modify it under the terms of the GNU General Public License as
103+ published by the Free Software Foundation; either version 2, or (at
104+ your option) any later version.
105+
106+ This program is distributed in the hope that it will be useful, but
107+ WITHOUT ANY WARRANTY; without even the implied warranty of
108+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109+ General Public License for more details.
110+*/
111+
112+#ifndef STRING_UTIL_H
113+#define STRING_UTIL_H
114+
115+#include <stddef.h>
116+
117+char *bin_to_hex(const void *bin_data, size_t len);
118+
119+#endif /* STRING_UTIL_H */
120--
1211.9.1
122
diff --git a/meta/recipes-devtools/opkg/opkg/0002-md5-Add-md5_to_string-function.patch b/meta/recipes-devtools/opkg/opkg/0002-md5-Add-md5_to_string-function.patch
new file mode 100644
index 0000000000..3b823c693c
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/0002-md5-Add-md5_to_string-function.patch
@@ -0,0 +1,110 @@
1From ecad8afab377d8be95eeaafc08afa228c8e030c3 Mon Sep 17 00:00:00 2001
2From: Paul Barker <paul@paulbarker.me.uk>
3Date: Sat, 7 Nov 2015 10:23:50 +0000
4Subject: [PATCH 2/4] md5: Add md5_to_string function
5
6Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
7Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com>
8
9Upstream-Status: Accepted
10---
11 libopkg/file_util.c | 28 +++-------------------------
12 libopkg/md5.c | 7 +++++++
13 libopkg/md5.h | 3 +++
14 3 files changed, 13 insertions(+), 25 deletions(-)
15
16diff --git a/libopkg/file_util.c b/libopkg/file_util.c
17index 5eff469..cb3dbf0 100644
18--- a/libopkg/file_util.c
19+++ b/libopkg/file_util.c
20@@ -349,27 +349,13 @@ int file_mkdir_hier(const char *path, long mode)
21
22 char *file_md5sum_alloc(const char *file_name)
23 {
24- static const int md5sum_bin_len = 16;
25- static const int md5sum_hex_len = 32;
26-
27- static const unsigned char bin2hex[16] = {
28- '0', '1', '2', '3',
29- '4', '5', '6', '7',
30- '8', '9', 'a', 'b',
31- 'c', 'd', 'e', 'f'
32- };
33-
34- int i, err;
35+ int err;
36 FILE *file;
37- char *md5sum_hex;
38- unsigned char md5sum_bin[md5sum_bin_len];
39-
40- md5sum_hex = xcalloc(1, md5sum_hex_len + 1);
41+ unsigned char md5sum_bin[16];
42
43 file = fopen(file_name, "r");
44 if (file == NULL) {
45 opkg_perror(ERROR, "Failed to open file %s", file_name);
46- free(md5sum_hex);
47 return NULL;
48 }
49
50@@ -377,20 +363,12 @@ char *file_md5sum_alloc(const char *file_name)
51 if (err) {
52 opkg_msg(ERROR, "Could't compute md5sum for %s.\n", file_name);
53 fclose(file);
54- free(md5sum_hex);
55 return NULL;
56 }
57
58 fclose(file);
59
60- for (i = 0; i < md5sum_bin_len; i++) {
61- md5sum_hex[i * 2] = bin2hex[md5sum_bin[i] >> 4];
62- md5sum_hex[i * 2 + 1] = bin2hex[md5sum_bin[i] & 0xf];
63- }
64-
65- md5sum_hex[md5sum_hex_len] = '\0';
66-
67- return md5sum_hex;
68+ return md5_to_string(md5sum_bin);
69 }
70
71 #ifdef HAVE_SHA256
72diff --git a/libopkg/md5.c b/libopkg/md5.c
73index d476b8b..bc2b229 100644
74--- a/libopkg/md5.c
75+++ b/libopkg/md5.c
76@@ -30,6 +30,8 @@
77 #include <string.h>
78 #include <sys/types.h>
79
80+#include "string_util.h"
81+
82 #if USE_UNLOCKED_IO
83 #include "unlocked-io.h"
84 #endif
85@@ -431,3 +433,8 @@ void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
86 ctx->C = C;
87 ctx->D = D;
88 }
89+
90+char *md5_to_string(const void *md5sum_bin)
91+{
92+ return bin_to_hex(md5sum_bin, 16);
93+}
94diff --git a/libopkg/md5.h b/libopkg/md5.h
95index 01320f5..2a7274d 100644
96--- a/libopkg/md5.h
97+++ b/libopkg/md5.h
98@@ -118,6 +118,9 @@ extern int __md5_stream(FILE * stream, void *resblock) __THROW;
99 extern void *__md5_buffer(const char *buffer, size_t len,
100 void *resblock) __THROW;
101
102+/* Convert a binary md5sum value to an ASCII string. */
103+char *md5_to_string(const void *md5sum_bin);
104+
105 #ifdef __cplusplus
106 }
107 #endif
108--
1091.9.1
110
diff --git a/meta/recipes-devtools/opkg/opkg/0003-sha256-Add-sha256_to_string-function.patch b/meta/recipes-devtools/opkg/opkg/0003-sha256-Add-sha256_to_string-function.patch
new file mode 100644
index 0000000000..16e82d7417
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/0003-sha256-Add-sha256_to_string-function.patch
@@ -0,0 +1,110 @@
1From 92e8378103bba3b91f2dec4e6fda3e1755a7c0fd Mon Sep 17 00:00:00 2001
2From: Paul Barker <paul@paulbarker.me.uk>
3Date: Sat, 7 Nov 2015 10:23:51 +0000
4Subject: [PATCH 3/4] sha256: Add sha256_to_string function
5
6Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
7Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com>
8
9Upstream-Status: Accepted
10---
11 libopkg/file_util.c | 28 +++-------------------------
12 libopkg/sha256.c | 7 +++++++
13 libopkg/sha256.h | 3 +++
14 3 files changed, 13 insertions(+), 25 deletions(-)
15
16diff --git a/libopkg/file_util.c b/libopkg/file_util.c
17index cb3dbf0..864aedb 100644
18--- a/libopkg/file_util.c
19+++ b/libopkg/file_util.c
20@@ -374,27 +374,13 @@ char *file_md5sum_alloc(const char *file_name)
21 #ifdef HAVE_SHA256
22 char *file_sha256sum_alloc(const char *file_name)
23 {
24- static const int sha256sum_bin_len = 32;
25- static const int sha256sum_hex_len = 64;
26-
27- static const unsigned char bin2hex[16] = {
28- '0', '1', '2', '3',
29- '4', '5', '6', '7',
30- '8', '9', 'a', 'b',
31- 'c', 'd', 'e', 'f'
32- };
33-
34- int i, err;
35+ int err;
36 FILE *file;
37- char *sha256sum_hex;
38- unsigned char sha256sum_bin[sha256sum_bin_len];
39-
40- sha256sum_hex = xcalloc(1, sha256sum_hex_len + 1);
41+ unsigned char sha256sum_bin[32];
42
43 file = fopen(file_name, "r");
44 if (file == NULL) {
45 opkg_perror(ERROR, "Failed to open file %s", file_name);
46- free(sha256sum_hex);
47 return NULL;
48 }
49
50@@ -402,20 +388,12 @@ char *file_sha256sum_alloc(const char *file_name)
51 if (err) {
52 opkg_msg(ERROR, "Could't compute sha256sum for %s.\n", file_name);
53 fclose(file);
54- free(sha256sum_hex);
55 return NULL;
56 }
57
58 fclose(file);
59
60- for (i = 0; i < sha256sum_bin_len; i++) {
61- sha256sum_hex[i * 2] = bin2hex[sha256sum_bin[i] >> 4];
62- sha256sum_hex[i * 2 + 1] = bin2hex[sha256sum_bin[i] & 0xf];
63- }
64-
65- sha256sum_hex[sha256sum_hex_len] = '\0';
66-
67- return sha256sum_hex;
68+ return sha256_to_string(sha256sum_bin);
69 }
70
71 #endif
72diff --git a/libopkg/sha256.c b/libopkg/sha256.c
73index 0816858..bceed72 100644
74--- a/libopkg/sha256.c
75+++ b/libopkg/sha256.c
76@@ -29,6 +29,8 @@
77 #include <stddef.h>
78 #include <string.h>
79
80+#include "string_util.h"
81+
82 #if USE_UNLOCKED_IO
83 #include "unlocked-io.h"
84 #endif
85@@ -517,3 +519,8 @@ void sha256_process_block(const void *buffer, size_t len,
86 h = ctx->state[7] += h;
87 }
88 }
89+
90+char *sha256_to_string(const void *sha256sum_bin)
91+{
92+ return bin_to_hex(sha256sum_bin, 32);
93+}
94diff --git a/libopkg/sha256.h b/libopkg/sha256.h
95index 734ab54..0d1e9e5 100644
96--- a/libopkg/sha256.h
97+++ b/libopkg/sha256.h
98@@ -85,6 +85,9 @@ extern int sha224_stream(FILE * stream, void *resblock);
99 extern void *sha256_buffer(const char *buffer, size_t len, void *resblock);
100 extern void *sha224_buffer(const char *buffer, size_t len, void *resblock);
101
102+/* Convert a binary sha256sum value to an ASCII string. */
103+char *sha256_to_string(const void *sha256sum_bin);
104+
105 #ifdef __cplusplus
106 }
107 #endif
108--
1091.9.1
110
diff --git a/meta/recipes-devtools/opkg/opkg/0004-opkg_download-Use-short-cache-file-name.patch b/meta/recipes-devtools/opkg/opkg/0004-opkg_download-Use-short-cache-file-name.patch
new file mode 100644
index 0000000000..7ea661dcf6
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/0004-opkg_download-Use-short-cache-file-name.patch
@@ -0,0 +1,85 @@
1From 61636f15718edc7ea17b91f22f1d97b905eaf951 Mon Sep 17 00:00:00 2001
2From: Paul Barker <paul@paulbarker.me.uk>
3Date: Sat, 7 Nov 2015 10:23:52 +0000
4Subject: [PATCH 4/4] opkg_download: Use short cache file name
5
6Source URIs can be very long. The cache directory itself may already have a very
7long path, especially if we're installing packages into an offline rootfs.
8Therefore it's not a good idea to simply tag the source URI onto the cache
9directory path to create a cache file name.
10
11To create shorter cache file names which are deterministic and very likely to be
12unique, we use the md5sum of the source URI along with the basename of the
13source URI. The basename is length limited to ensure that it the resulting
14filename length is always reasonable.
15
16Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
17Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com>
18
19Upstream-Status: Accepted
20---
21 libopkg/opkg_download.c | 35 ++++++++++++++++++++++++++++-------
22 1 file changed, 28 insertions(+), 7 deletions(-)
23
24diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
25index e9b86a5..a37b10d 100644
26--- a/libopkg/opkg_download.c
27+++ b/libopkg/opkg_download.c
28@@ -29,10 +29,18 @@
29 #include "opkg_verify.h"
30 #include "opkg_utils.h"
31
32+#include "md5.h"
33 #include "sprintf_alloc.h"
34 #include "file_util.h"
35 #include "xfuncs.h"
36
37+/* Limit the short file name used to generate cache file names to 90 characters
38+ * so that when added to the md5sum (32 characters) and an underscore, the
39+ * resulting length is below 128 characters. The maximum file name length
40+ * differs between plaforms but 128 characters should be reasonable.
41+ */
42+#define MAX_SHORT_FILE_NAME_LENGTH 90
43+
44 static int opkg_download_set_env()
45 {
46 int r;
47@@ -135,15 +143,28 @@ int opkg_download_internal(const char *src, const char *dest,
48 */
49 char *get_cache_location(const char *src)
50 {
51- char *cache_name = xstrdup(src);
52- char *cache_location, *p;
53+ unsigned char md5sum_bin[16];
54+ char *md5sum_hex;
55+ char *cache_location;
56+ char *short_file_name;
57+ char *tmp = xstrdup(src);
58
59- for (p = cache_name; *p; p++)
60- if (*p == '/')
61- *p = '_';
62+ md5_buffer(src, strlen(src), md5sum_bin);
63+ md5sum_hex = md5_to_string(md5sum_bin);
64
65- sprintf_alloc(&cache_location, "%s/%s", opkg_config->cache_dir, cache_name);
66- free(cache_name);
67+ /* Generate a short file name which will be used along with an md5sum of the
68+ * full src URI in the cache file name. This short file name is limited to
69+ * MAX_SHORT_FILE_NAME_LENGTH to ensure that the total cache file name
70+ * length is reasonable.
71+ */
72+ short_file_name = basename(tmp);
73+ if (strlen(short_file_name) > MAX_SHORT_FILE_NAME_LENGTH)
74+ short_file_name[MAX_SHORT_FILE_NAME_LENGTH] = '\0';
75+
76+ sprintf_alloc(&cache_location, "%s/%s_%s", opkg_config->cache_dir,
77+ md5sum_hex, short_file_name);
78+ free(md5sum_hex);
79+ free(tmp);
80 return cache_location;
81 }
82
83--
841.9.1
85
diff --git a/meta/recipes-devtools/opkg/opkg_0.3.0.bb b/meta/recipes-devtools/opkg/opkg_0.3.0.bb
index 588250e456..5ad3e92cff 100644
--- a/meta/recipes-devtools/opkg/opkg_0.3.0.bb
+++ b/meta/recipes-devtools/opkg/opkg_0.3.0.bb
@@ -17,6 +17,10 @@ SRC_URI = "http://downloads.yoctoproject.org/releases/${BPN}/${BPN}-${PV}.tar.gz
17 file://0001-opkg_archive-add-support-for-empty-compressed-files.patch \ 17 file://0001-opkg_archive-add-support-for-empty-compressed-files.patch \
18 file://0001-libopkg-include-stdio.h-for-getting-FILE-defined.patch \ 18 file://0001-libopkg-include-stdio.h-for-getting-FILE-defined.patch \
19 file://0001-opkg_conf-create-opkg.lock-in-run-instead-of-var-run.patch \ 19 file://0001-opkg_conf-create-opkg.lock-in-run-instead-of-var-run.patch \
20 file://0001-string_util-New-file-with-bin_to_hex-function.patch \
21 file://0002-md5-Add-md5_to_string-function.patch \
22 file://0003-sha256-Add-sha256_to_string-function.patch \
23 file://0004-opkg_download-Use-short-cache-file-name.patch \
20" 24"
21 25
22SRC_URI[md5sum] = "3412cdc71d78b98facc84b19331ec64e" 26SRC_URI[md5sum] = "3412cdc71d78b98facc84b19331ec64e"