diff --git a/apps/addressbook/java/src/net/i2p/addressbook/AddressBook.java b/apps/addressbook/java/src/net/i2p/addressbook/AddressBook.java index 6249cadaa0c59fb8014099337a2f3aa0162fe64f..30536f4ae43c32d85313350706e706c89fc06829 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/AddressBook.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/AddressBook.java @@ -196,6 +196,8 @@ public class AddressBook { // null cert ends with AAAA but other zero-length certs would be AA ((dest.length() == MIN_DEST_LENGTH && dest.endsWith("AA")) || (dest.length() > MIN_DEST_LENGTH && dest.length() <= MAX_DEST_LENGTH)) && + // B64 comes in groups of 2, 3, or 4 chars, but never 1 + ((dest.length() % 4) != 1) && dest.replaceAll("[a-zA-Z0-9~-]", "").length() == 0 ; } @@ -253,6 +255,7 @@ public class AddressBook { try { ConfigParser.write(this.addresses, file); } catch (IOException exp) { + System.err.println("Error writing addressbook " + file.getAbsolutePath() + " : " + exp.toString()); } } } diff --git a/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java b/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java index 6c95e2e19653f90dc31065232e50a297354ee1c8..c963ecce5456118324ae33cc5a249051da5397fd 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java @@ -269,7 +269,9 @@ public class ConfigParser { /** * Write contents of Map map to the File file. Output is written * with one key, value pair on each line, in the format: key=value. - * + * Write to a temp file in the same directory and then rename, to not corrupt + * simultaneous accesses by the router. + * * @param map * A Map to write to file. * @param file @@ -278,8 +280,17 @@ public class ConfigParser { * if file cannot be written to. */ public static void write(Map map, File file) throws IOException { + File tmp = File.createTempFile("hoststxt-", ".tmp", file.getAbsoluteFile().getParentFile()); ConfigParser + .write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(tmp), "UTF-8"))); + boolean success = tmp.renameTo(file); + if (!success) { + // hmm, that didn't work, try it the old way + System.out.println("Warning: addressbook rename fail from " + tmp + " to " + file); + tmp.delete(); + ConfigParser .write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "UTF-8"))); + } } /**