Fixed npe in wormarc cli tool. Added a launch script for it.
diff --git a/alien/src/wormarc/cli/CLI.java b/alien/src/wormarc/cli/CLI.java --- a/alien/src/wormarc/cli/CLI.java +++ b/alien/src/wormarc/cli/CLI.java @@ -52,7 +52,17 @@ import wormarc.io.FreenetTopKey; public class CLI { private static final PrintStream sOut = System.out; private final static String FCP_HOST = "127.0.0.1"; - private final static int FCP_PORT = 19481; + private final static int FCP_PORT = 9481; + + private static String getFcpHost() { + return System.getProperty("wormarc.cli.fms.host", FCP_HOST); + } + + private static int getFcpPort() { + // This reads an integer System property. wtf? + // Whoever designed this API was hitting the pipe hard. + return Integer.getInteger("wormarc.cli.fms.port", FCP_PORT); + } private static CLICache getCache(boolean createCache) throws IOException { String cwd = (new File(".")).getCanonicalPath(); @@ -370,7 +380,7 @@ public class CLI { sOut.println(String.format("Searching for %d links... ", chain.size())); - FreenetIO freenetResolver = new FreenetIO(FCP_HOST, FCP_PORT, cache); + FreenetIO freenetResolver = new FreenetIO(getFcpHost(), getFcpPort(), cache); List<ExternalRefs.Reference> refs = AuditArchive.history(archive, @@ -396,7 +406,7 @@ public class CLI { sOut.println("Couldn't read remote. Don't know what version to start from."); } - FreenetIO freenetResolver = new FreenetIO(FCP_HOST, FCP_PORT, cache); + FreenetIO freenetResolver = new FreenetIO(getFcpHost(), getFcpPort(), cache); Archive archive = freenetResolver.resolve(remote); AuditArchive.ChangeLogCallback callback = new AuditArchive.ChangeLogCallback () { public boolean onChangeEntry(ExternalRefs.Reference oldVer, @@ -507,7 +517,7 @@ public class CLI { } } - FreenetIO io = new FreenetIO(FCP_HOST, FCP_PORT, cache); + FreenetIO io = new FreenetIO(getFcpHost(), getFcpPort(), cache); io.setInsertUri(insertUri); sOut.println(String.format("Pushing version: %s to Freenet Insert URI:", cache.getName())); sOut.println(insertUri); @@ -523,7 +533,7 @@ public class CLI { public boolean canParse(String[] args) { return args.length == 2; } public void invoke(String[] args, CLICache cache) throws Exception { String requestUri = args[1]; - FreenetIO io = new FreenetIO(FCP_HOST, FCP_PORT, cache); + FreenetIO io = new FreenetIO(getFcpHost(), getFcpPort(), cache); io.setRequestUri(requestUri); sOut.println(String.format("Reading: %s", requestUri)); Archive archive = Archive.load(io); @@ -539,7 +549,7 @@ public class CLI { public boolean canParse(String[] args) { return args.length == 2; } public void invoke(String[] args, CLICache cache) throws Exception { String requestUri = args[1]; - FreenetIO io = new FreenetIO(FCP_HOST, FCP_PORT, cache); + FreenetIO io = new FreenetIO(getFcpHost(), getFcpPort(), cache); sOut.println(String.format("Reading Top Key: %s", requestUri)); FreenetTopKey topKey = io.readTopKey(requestUri); sOut.println(String.format("Version: %s", topKey.mVersion)); diff --git a/alien/src/wormarc/io/FreenetIO.java b/alien/src/wormarc/io/FreenetIO.java --- a/alien/src/wormarc/io/FreenetIO.java +++ b/alien/src/wormarc/io/FreenetIO.java @@ -50,7 +50,8 @@ import wormarc.RootObjectKind; public class FreenetIO implements Archive.IO, ArchiveResolver { private LinkCache mCache; - private Map<String, String> mSha1ToChk; + // Final on purpose. Look at sleazy threading code before making non-final! + private final Map<String, String> mSha1ToChk; // Transient private HistoryLinkMap mLinkMap; @@ -363,6 +364,9 @@ public class FreenetIO implements Archiv //////////////////////////////////////////////////////////// private void cacheBlockChk(String hexDigest, String chk) { + if (mSha1ToChk == null) { + return; + } synchronized(mSha1ToChk) { debug(String.format("cached: %s -> %s", hexDigest, chk)); mSha1ToChk.put(hexDigest, chk); @@ -370,6 +374,9 @@ public class FreenetIO implements Archiv } private String getCachedChk(String hexDigest) { + if (mSha1ToChk == null) { + return null; + } synchronized(mSha1ToChk) { if (hexDigest == null) { return null; diff --git a/script/wa.sh b/script/wa.sh new file mode 100755 --- /dev/null +++ b/script/wa.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +# CAREFUL: This tool can delete everything in +# the current directory if you ask it to. +# Use it at your own peril. + +export set FCP_HOST="127.0.0.1" +export set FCP_PORT="9481" + +# Deal with symlinks. +export set FULL_SCRIPT_PATH=`readlink -e $0` +export set SCRIPT_DIR=`dirname ${FULL_SCRIPT_PATH}` + +# This doesn't work if you symlink to the script. +# That's why I used the hacks above. +#export set SCRIPT_DIR=`dirname $0` + +. "${SCRIPT_DIR}/setup_env.sh" + +${JAVA_CMD} -Dwormarc.cli.fms.host=${FCP_HOST} -Dwormarc.cli.fms.port=${FCP_PORT} \ + -classpath ${JAR_FILE}:${FN_JAR_FILE} wormarc.cli.CLI "$@" +