download: remove compatibility with old cache naming scheme
authorBaptiste Jonglez <git@bitsofnetworks.org>
Mon, 24 Aug 2020 23:00:28 +0000 (01:00 +0200)
committerBaptiste Jonglez <git@bitsofnetworks.org>
Sun, 31 Jan 2021 09:56:03 +0000 (10:56 +0100)
A long time ago, the name of cached files was derived from the source URL.
This was changed in 2011 with d46db43e21 ("Don't include the source URI in
the cached filename.")

Some compatibility code was left behind: even today, we are still trying
to read from the old filename.  The goal of this compatibility code was to
account for existing caches that still had files with the old naming
scheme.

More than 9 years later, it is safe to remove this compatibility code.
It simplifies the download code and avoids a useless disk access.

Signed-off-by: Baptiste Jonglez <git@bitsofnetworks.org>
(cherry picked from commit a786e25f5cbcb9372864a4edf12b7e80774c4514)

libopkg/opkg_download.c

index e9705065aa76e85c63f7c6eef3223638ce313415..97df37f909fcca6862ed436ed28da496c41039b0 100644 (file)
@@ -131,8 +131,7 @@ opkg_download(const char *src, const char *dest_file_name,
 static int
 opkg_download_cache(const char *src, const char *dest_file_name)
 {
-       char *cache_name = xstrdup(src);
-       char *cache_location, *p;
+       char *cache_name, *cache_location;
        int err = 0;
 
        if (!conf->cache || str_starts_with(src, "file:")) {
@@ -146,32 +145,19 @@ opkg_download_cache(const char *src, const char *dest_file_name)
                goto out1;
        }
 
-       for (p = cache_name; *p; p++)
-               if (*p == '/')
-                       *p = ',';       /* looks nicer than | or # */
-
+       char *filename = strrchr(dest_file_name, '/');
+       if (filename)
+               cache_name = xstrdup(filename + 1);     // strip leading '/'
+       else
+               cache_name = xstrdup(dest_file_name);
        sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name);
        if (file_exists(cache_location))
                opkg_msg(NOTICE, "Copying %s.\n", cache_location);
        else {
-               /* 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, 0);
-                       if (err) {
-                               (void)unlink(cache_location);
-                               goto out2;
-                       }
+               err = opkg_download(src, cache_location, 0);
+               if (err) {
+                       (void)unlink(cache_location);
+                       goto out2;
                }
        }
 
@@ -179,8 +165,8 @@ opkg_download_cache(const char *src, const char *dest_file_name)
 
 out2:
        free(cache_location);
-out1:
        free(cache_name);
+out1:
        return err;
 }