Changes between Version 1 and Version 2 of Ticket #18569, comment 2


Ignore:
Timestamp:
2020-12-12T20:53:21+01:00 (5 years ago)
Author:
michael2402

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #18569, comment 2

    v1 v2  
    66Fix is simple.
    77
    8 In Preferences.xml, replace
     8In Preferences.java, replace
    99{{{
    1010        Utils.copyFile(tmpFile, prefFile);
     
    1717
    1818A move is atomic (either works completely or not), while a copy can corrupt the preferences file.
     19
     20
     21------------------
     22Patch
     23{{{
     24Index: src/org/openstreetmap/josm/data/Preferences.java
     25===================================================================
     26--- src/org/openstreetmap/josm/data/Preferences.java    (Revision 17404)
     27+++ src/org/openstreetmap/josm/data/Preferences.java    (Arbeitskopie)
     28@@ -13,7 +13,9 @@
     29 import java.io.Reader;
     30 import java.io.StringWriter;
     31 import java.nio.charset.StandardCharsets;
     32+import java.nio.file.Files;
     33 import java.nio.file.InvalidPathException;
     34+import java.nio.file.StandardCopyOption;
     35 import java.util.ArrayList;
     36 import java.util.Arrays;
     37 import java.util.Collection;
     38@@ -447,7 +449,7 @@
     39         }
     40 
     41         File tmpFile = new File(prefFile + "_tmp");
     42-        Utils.copyFile(tmpFile, prefFile);
     43+        Files.move(tmpFile.toPath(), prefFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
     44         Utils.deleteFile(tmpFile, marktr("Unable to delete temporary file {0}"));
     45 
     46         setCorrectPermissions(prefFile);
     47}}}