commit 421f38eeb95ba86d8b2f3007f62a111dc090d991 Author: iwakeh iwakeh@torproject.org Date: Wed Oct 19 12:12:06 2016 +0200
Implements task-20039: DescriptorIndexCollector now accepts a URL path. If only a base URL is given, try to retrieve 'index/index.json' from the given host URL. --- .../descriptor/index/DescriptorIndexCollector.java | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java b/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java index 4f62be6..d32f811 100644 --- a/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java +++ b/src/main/java/org/torproject/descriptor/index/DescriptorIndexCollector.java @@ -33,12 +33,14 @@ public class DescriptorIndexCollector implements DescriptorCollector { .getLogger(DescriptorIndexCollector.class);
/** - * The parameter usage differs from the interface: - * <code>collecTorIndexUrl</code> is expected to contain the URL - * for an index JSON file (plain or compressed). + * If <code>collecTorIndexUrlString</code> contains just the + * base url, e.g. https://some.host.org, the path + * <code>/index/index.json</code> will be appended. + * If a path is given (even just a final slash, e.g. https://some.host.org/), + * the <code>collecTorIndexUrlString</code> will be used as is. */ @Override - public void collectDescriptors(String collecTorIndexUrl, + public void collectDescriptors(String collecTorIndexUrlString, String[] remoteDirectories, long minLastModified, File localDirectory, boolean deleteExtraneousLocalFiles) { if (minLastModified < 0) { @@ -52,11 +54,18 @@ public class DescriptorIndexCollector implements DescriptorCollector { SortedMap<String, Long> localFiles = statLocalDirectory(localDirectory); SortedMap<String, FileNode> remoteFiles = null; IndexNode index = null; + String indexUrlString = ""; try { - index = IndexNode.fetchIndex(collecTorIndexUrl); + URL indexUrl = new URL(collecTorIndexUrlString); + indexUrlString = indexUrl.toString(); + if (indexUrl.getPath().isEmpty()) { + indexUrlString += "/index/index.json"; + } + index = IndexNode.fetchIndex(indexUrlString); remoteFiles = index.retrieveFilesIn(remoteDirectories); - } catch (Exception ioe) { - throw new RuntimeException("Cannot fetch index. ", ioe); + } catch (Exception ex) { + throw new RuntimeException("Cannot fetch index from '" + + indexUrlString + "'.", ex); } this.fetchRemoteFiles(index.path, remoteFiles, minLastModified, localDirectory, localFiles);
tor-commits@lists.torproject.org