aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-devtools/opkg/files/0003-opkg_download-Use-md5sum-of-src-URI-as-cache-file-na.patch
blob: c7e5cdb9ffbf00c6483f4d745a095e9f8dc9a8f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
From 2ba39321c686547588745a8ff7d35c6e1965c734 Mon Sep 17 00:00:00 2001
From: Paul Barker <pa...@paulbarker.me.uk>
Date: Sat, 24 Oct 2015 20:15:19 +0100
Subject: [PATCH 3/3] opkg_download: Use md5sum of src URI as cache file name

Source URIs can be very long. The cache directory itself may already have a very
long path, especially if we're installing packages into an offline rootfs.
Therefore it's not a good idea to simply tag the source URI onto the cache
directory path to create a cache file name.

To create shorter cache file names which are deterministic and very likely to be
unique, we use the md5sum of the source URI.

Signed-off-by: Paul Barker <pa...@paulbarker.me.uk>
---
 libopkg/opkg_download.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
index e9b86a5..d270074 100644
--- a/libopkg/opkg_download.c
+++ b/libopkg/opkg_download.c
@@ -29,6 +29,7 @@
 #include "opkg_verify.h"
 #include "opkg_utils.h"
 
+#include "md5.h"
 #include "sprintf_alloc.h"
 #include "file_util.h"
 #include "xfuncs.h"
@@ -135,12 +136,12 @@ int opkg_download_internal(const char *src, const char *dest,
  */
 char *get_cache_location(const char *src)
 {
-    char *cache_name = xstrdup(src);
-    char *cache_location, *p;
+    unsigned char md5sum_bin[16];
+    char *cache_name;
+    char *cache_location;
 
-    for (p = cache_name; *p; p++)
-        if (*p == '/')
-            *p = '_';
+    md5_buffer(src, strlen(src), md5sum_bin);
+    cache_name = md5_to_string(md5sum_bin);
 
     sprintf_alloc(&cache_location, "%s/%s", opkg_config->cache_dir, cache_name);
     free(cache_name);
-- 
2.6.1