From 2ba39321c686547588745a8ff7d35c6e1965c734 Mon Sep 17 00:00:00 2001 From: Paul Barker 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 --- 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