From 47c88873d2d13652786751464abbeace5899ec1c Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 19 Sep 2019 08:26:13 +0200 Subject: [PATCH] cache save/load workflow --- changelog.md | 1 + src/be/nikiroo/utils/Cache.java | 7 +++++-- src/be/nikiroo/utils/Downloader.java | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 3fcdb762..0831070c 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 779b194f..62330827 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 b1ac56c0..c9a319aa 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( -- 2.27.0