Changeset 9e8af73


Ignore:
Timestamp:
Nov 21, 2010 8:40:42 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2a34ea83
Parents:
106af99
Message:
  • Addressbook: Fix rename error on Windows (tkt 323 - thanks RN!)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/addressbook/java/src/net/i2p/addressbook/ConfigParser.java

    r106af99 r9e8af73  
    5050class ConfigParser {
    5151
     52    private static final boolean isWindows = System.getProperty("os.name").startsWith("Win");
     53
    5254    /**
    5355     * Strip the comments from a String. Lines that begin with '#' and ';' are
     
    277279     * with one key, value pair on each line, in the format: key=value.
    278280     * Write to a temp file in the same directory and then rename, to not corrupt
    279      * simultaneous accesses by the router.
     281     * simultaneous accesses by the router. Except on Windows where renameTo()
     282     * will fail if the target exists.
    280283     *
    281284     * @param map
     
    287290     */
    288291    public static void write(Map map, File file) throws IOException {
    289         File tmp = SecureFile.createTempFile("hoststxt-", ".tmp", file.getAbsoluteFile().getParentFile());
    290         ConfigParser
     292        boolean success = false;
     293        if (!isWindows) {
     294            File tmp = SecureFile.createTempFile("temp-", ".tmp", file.getAbsoluteFile().getParentFile());
     295            ConfigParser
    291296                .write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(tmp), "UTF-8")));
    292         boolean success = tmp.renameTo(file);
     297            success = tmp.renameTo(file);
     298            if (!success) {
     299                tmp.delete();
     300                //System.out.println("Warning: addressbook rename fail from " + tmp + " to " + file);
     301            }
     302        }
    293303        if (!success) {
    294304            // hmm, that didn't work, try it the old way
    295             System.out.println("Warning: addressbook rename fail from " + tmp + " to " + file);
    296             tmp.delete();
    297305            ConfigParser
    298306                .write(map, new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(file), "UTF-8")));
Note: See TracChangeset for help on using the changeset viewer.