Permalink
Browse files

Ensure MuzeiArtProviders recover from the cache being cleared

When the cache is cleared, the directory MuzeiArtProvider stores cached artwork in is deleted, causing FileOutputStream to fail when re-downloading the file. By ensuring that the cache directory is created before calling FileOutputStream, we can redownload artwork lost when the cache was cleared.
  • Loading branch information...
ianhanniballake committed Oct 5, 2018
1 parent 81fea42 commit 61b5bae404e411710bad037425a191f5785c4d3a
@@ -877,10 +877,16 @@ public final ParcelFileDescriptor openFile(
}
artwork = Artwork.fromCursor(data);
}
//noinspection ConstantConditions
if (!artwork.getData().exists() && mode.equals("r")) {
// Download the image from the persistent URI for read-only operations
// rather than throw a FileNotFoundException
File directory = artwork.getData().getParentFile();
// Ensure that the parent directory of the artwork exists
// as otherwise FileOutputStream will fail
if (!directory.exists() && !directory.mkdirs()) {
throw new FileNotFoundException("Unable to create directory " +
directory + " for " + artwork);
}
try (InputStream in = openFile(artwork);
FileOutputStream out = new FileOutputStream(artwork.getData())) {
byte[] buffer = new byte[1024];

0 comments on commit 61b5bae

Please sign in to comment.