From d46db43e215d8f3b26e04c99f113db065040ef4c Mon Sep 17 00:00:00 2001 From: "graham.gower@gmail.com" Date: Fri, 8 Apr 2011 04:30:10 +0000 Subject: [PATCH] Don't include the source URI in the cached filename. This avoids multiple downloads in the case where a repository is simply a mirror of another. The old, uri mangled, filename is still checked to ensure backwards compatibility with existing caches. Patch from robert.melchers@gmail.com. git-svn-id: http://opkg.googlecode.com/svn/trunk@617 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- libopkg/opkg_download.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index b9533aa..a1b8341 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -215,10 +215,23 @@ opkg_download_cache(const char *src, const char *dest_file_name, if (file_exists(cache_location)) opkg_msg(NOTICE, "Copying %s.\n", cache_location); else { - err = opkg_download(src, cache_location, cb, data, 0); - if (err) { - (void) unlink(cache_location); - goto out2; + /* cache file with funky name not found, try simple name */ + free(cache_name); + char *filename = strrchr(dest_file_name,'/'); + if (filename) + cache_name = xstrdup(filename+1); // strip leading '/' + else + cache_name = xstrdup(dest_file_name); + free(cache_location); + sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name); + if (file_exists(cache_location)) + opkg_msg(NOTICE, "Copying %s.\n", cache_location); + else { + err = opkg_download(src, cache_location, cb, data); + if (err) { + (void) unlink(cache_location); + goto out2; + } } } -- 2.30.2