From 297fdb60d3b3622ed2b3a48c4e6061b23e47f720 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 22 Nov 2015 21:26:18 +0100 Subject: [PATCH] throw exception if crawler hostqueue can't create hostpath directory. In rare cases hostname may not be a valid filesystem directory name, which can't be created (e.g. containing '*' char). To prevent crawl queue looping on this invalid entry by throwing a malformedurlexception. --- source/net/yacy/crawler/HostQueue.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/source/net/yacy/crawler/HostQueue.java b/source/net/yacy/crawler/HostQueue.java index 3638f4534..105b0c53d 100644 --- a/source/net/yacy/crawler/HostQueue.java +++ b/source/net/yacy/crawler/HostQueue.java @@ -77,7 +77,7 @@ public class HostQueue implements Balancer { final String hostName, final int port, final boolean onDemand, - final boolean exceed134217727) { + final boolean exceed134217727) throws MalformedURLException { this.onDemand = onDemand; this.exceed134217727 = exceed134217727; this.hostName = (hostName == null) ? "localhost" : hostName; // might be null (file://) but hostqueue needs a name (for queue file) @@ -89,7 +89,7 @@ public class HostQueue implements Balancer { public HostQueue ( final File hostPath, final boolean onDemand, - final boolean exceed134217727) { + final boolean exceed134217727) throws MalformedURLException { this.onDemand = onDemand; this.exceed134217727 = exceed134217727; this.hostPath = hostPath; @@ -102,7 +102,7 @@ public class HostQueue implements Balancer { init(); } - private final void init() { + private final void init() throws MalformedURLException { try { if (this.hostName == null) this.hostHash=""; @@ -111,7 +111,12 @@ public class HostQueue implements Balancer { } catch (MalformedURLException e) { this.hostHash = ""; } - if (!(this.hostPath.exists())) this.hostPath.mkdirs(); + if (!(this.hostPath.exists())) { + this.hostPath.mkdirs(); + if (!this.hostPath.exists()) { // check if directory created (if not, likely a name violation) + throw new MalformedURLException("hostPath could not be created: " + this.hostPath.toString()); + } + } this.depthStacks = new TreeMap(); int size = openAllStacks(); if (log.isInfo()) log.info("opened HostQueue " + this.hostPath.getAbsolutePath() + " with " + size + " urls.");