Don't include the source URI in the cached filename.
authorgraham.gower@gmail.com <graham.gower@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Fri, 8 Apr 2011 04:30:10 +0000 (04:30 +0000)
committergraham.gower@gmail.com <graham.gower@gmail.com@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Fri, 8 Apr 2011 04:30:10 +0000 (04:30 +0000)
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

index b9533aa87a324f725f199815ff6f64d4e9ad38dd..a1b83416bffde9382e78c5be66ee071226d57269 100644 (file)
@@ -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;
+         }
        }
     }