Changeset 3276 in osm


Ignore:
Timestamp:
2007-06-20T14:23:23+02:00 (17 years ago)
Author:
christofd
Message:

make backup before saving

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/AutoSaveGpsLayerTimerTask.java

    r2974 r3276  
    5858    @Override
    5959    public void run() {
    60         System.out.println("AutoSaving data to file " + file.getAbsolutePath());
    6160
    62         try {
     61        try {           
    6362            XmlWriter.OsmWriterInterface writer = getXmlWriter();
    6463            if(writer != null) {
     64                // write to temporary file, on success, rename tmp file to target file:
     65                File tmpFile = new File(file.getAbsoluteFile()+".tmp");
     66                System.out.println("AutoSaving data to file " + file.getAbsolutePath());
    6567                // synchronize on layer to prevent concurrent adding of data to the layer
    6668                // quite a hack, but no other object to sync available :-(
    6769                // @see LiveGpsLayer
    6870                synchronized(LiveGpsLock.class) {
    69                     XmlWriter.output(new FileOutputStream(file), writer);
    70                 }               
     71                    XmlWriter.output(new FileOutputStream(tmpFile), writer);
     72                }   
     73                tmpFile.renameTo(file);
    7174            }
    7275        } catch (IOException x) {
Note: See TracChangeset for help on using the changeset viewer.