X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FCache.java;h=111fc769b9a5ded89c772d0ff2ede551cfcf080c;hp=dcbde74ea4b053ae512c7ed9149114af5f4aa77e;hb=805005449dacb1e7b825db63836bf100e472ddd0;hpb=530d4062471346d6ececf76d74a0358c91323998 diff --git a/src/be/nikiroo/utils/Cache.java b/src/be/nikiroo/utils/Cache.java index dcbde74..111fc76 100644 --- a/src/be/nikiroo/utils/Cache.java +++ b/src/be/nikiroo/utils/Cache.java @@ -70,6 +70,10 @@ public class Cache { * the new traces handler */ public void setTraceHandler(TraceHandler tracer) { + if (tracer == null) { + tracer = new TraceHandler(false, false, false); + } + this.tracer = tracer; } @@ -89,7 +93,7 @@ public class Cache { */ public boolean check(URL url, boolean allowTooOld, boolean stable) { File file = getCached(url); - if (file.exists()) { + if (file.exists() && file.isFile()) { if (allowTooOld || !isOld(file, stable)) { return true; } @@ -190,7 +194,8 @@ public class Cache { * @return the opened resource if found, NULL if not */ private InputStream load(File cached, boolean allowTooOld, boolean stable) { - if (cached.exists() && (allowTooOld || !isOld(cached, stable))) { + if (cached.exists() && cached.isFile() + && (allowTooOld || !isOld(cached, stable))) { try { return new MarkableFileInputStream(new FileInputStream(cached)); } catch (FileNotFoundException e) { @@ -328,7 +333,11 @@ public class Cache { if (name == null || name.isEmpty()) { // File File file = new File(url.getFile()); - subdir = new File(file.getParent().replace("..", "__")); + if (file.getParent() == null) { + subdir = new File("+"); + } else { + subdir = new File(file.getParent().replace("..", "__")); + } subdir = new File(dir, allowedChars(subdir.getPath())); name = allowedChars(url.getFile()); } else {