From: Niki Roo Date: Thu, 19 Sep 2019 06:26:13 +0000 (+0200) Subject: cache save/load workflow X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=commitdiff_plain;h=47c88873d2d13652786751464abbeace5899ec1c cache save/load workflow --- diff --git a/changelog.md b/changelog.md index 3fcdb76..0831070 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## Version WIP - Downloader: new Offline mode for cache accesses only +- Cache: make sure an immedate SAVE/LOAD always work, even with 0 retention delays ## Version 5.0.0 diff --git a/src/be/nikiroo/utils/Cache.java b/src/be/nikiroo/utils/Cache.java index 779b194..6233082 100644 --- a/src/be/nikiroo/utils/Cache.java +++ b/src/be/nikiroo/utils/Cache.java @@ -326,9 +326,12 @@ public class Cache { * in case of I/O error */ private long save(InputStream in, File cached) throws IOException { - // We delete AFTER so not to remove the subdir we will use... - long bytes = IOUtils.write(in, cached); + // We want to force at least an immediate SAVE/LOAD to work for some + // workflows, even if we don't accept cached files (times set to "0" + // -- and not "-1" or a positive value) clean(true, dir, 10); + cached.getParentFile().mkdirs(); // in case we deleted our own parent + long bytes = IOUtils.write(in, cached); return bytes; } diff --git a/src/be/nikiroo/utils/Downloader.java b/src/be/nikiroo/utils/Downloader.java index b1ac56c..c9a319a 100644 --- a/src/be/nikiroo/utils/Downloader.java +++ b/src/be/nikiroo/utils/Downloader.java @@ -397,6 +397,11 @@ public class Downloader { } } + if (in == null) { + throw new IOException( + "Cannot retrieve the file after storing it in the cache (??)"); + } + return in; } catch (IOException e) { throw new IOException(String.format(