Include an images full URL in the cache path.

All feature graphics are called `featureGraphic.png`, and so our cache
was presuming all feature graphics were the same image. By including
the full path from the server in the cached name, we don't overwrite
images any more.
This commit is contained in:
Peter Serwylo 2017-05-09 09:49:13 +10:00
parent bd5503b4cd
commit 67a29bae8f
2 changed files with 10 additions and 2 deletions

View File

@ -54,6 +54,7 @@ import org.fdroid.fdroid.compat.PRNGFixes;
import org.fdroid.fdroid.data.AppProvider; import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.InstalledAppProviderService; import org.fdroid.fdroid.data.InstalledAppProviderService;
import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.SanitizedFile;
import org.fdroid.fdroid.installer.InstallHistoryService; import org.fdroid.fdroid.installer.InstallHistoryService;
import org.fdroid.fdroid.net.ImageLoaderForUIL; import org.fdroid.fdroid.net.ImageLoaderForUIL;
import org.fdroid.fdroid.net.WifiStateChangeService; import org.fdroid.fdroid.net.WifiStateChangeService;
@ -282,7 +283,7 @@ public class FDroidApp extends Application {
if (TextUtils.isEmpty(imageUri)) { if (TextUtils.isEmpty(imageUri)) {
return "null"; return "null";
} else { } else {
return imageUri.substring(imageUri.lastIndexOf('/') + 1); return SanitizedFile.sanitizeFileName(Uri.parse(imageUri).getPath().replaceAll("/", "-"));
} }
} }
}, },

View File

@ -11,13 +11,20 @@ import java.io.File;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class SanitizedFile extends File { public class SanitizedFile extends File {
/**
* Removes anything that is not an alpha numeric character, or one of "-", ".", or "_".
*/
public static String sanitizeFileName(String name) {
return name.replaceAll("[^A-Za-z0-9-._]", "");
}
/** /**
* The "name" argument is assumed to be a file name, _not including any path separators_. * The "name" argument is assumed to be a file name, _not including any path separators_.
* If it is a relative path to be appended to "parent", such as "/blah/sneh.txt", then * If it is a relative path to be appended to "parent", such as "/blah/sneh.txt", then
* the forward slashes will be removed and it will be assumed you meant "blahsneh.txt". * the forward slashes will be removed and it will be assumed you meant "blahsneh.txt".
*/ */
public SanitizedFile(File parent, String name) { public SanitizedFile(File parent, String name) {
super(parent, name.replaceAll("[^A-Za-z0-9-._]", "")); super(parent, sanitizeFileName(name));
} }
/** /**