Changeset 3686 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-11-30T23:59:57+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r3679 r3686 35 35 /** 36 36 * Saves data layers periodically so they can be recovered in case of a crash. 37 * 38 * There are 2 directories 39 * - autosave dir: copies of the currently open data layers are saved here every 40 * PROP_INTERVAL seconds. When a data layer is closed normally, the corresponding 41 * files are removed. If this dir is non-empty on start, JOSM assumes 42 * that it crashed last time. 43 * - deleted layers dir: "secondary archive" - when autosaved layers are restored 44 * they are copied to this directory. We cannot keep them in the autosave folder, 45 * but just deleting it would be dangerous: Maybe a feature inside the file 46 * caused JOSM to crash. If the data is valuable, the user can still try to 47 * open with another versions of JOSM or fix the problem manually. 48 * 49 * The deleted layers dir keeps at most PROP_DELETED_LAYERS files. 37 50 */ 38 51 public class AutosaveTask extends TimerTask implements LayerChangeListener, Listener { … … 78 91 79 92 for (File f: deletedLayersDir.listFiles()) { 80 deletedLayers.add(f); 81 } 82 93 deletedLayers.add(f); // FIXME: sort by mtime 94 } 83 95 84 96 timer = new Timer(true); … … 243 255 List<File> result = new ArrayList<File>(); 244 256 File[] files = autosaveDir.listFiles(); 245 System.err.println("autosave debug (getUnsavedLayersFiles) files="+(files == null ? null : Arrays.toString(files)));246 257 if (files == null) 247 258 return result; 248 259 for (File file: files) { 249 System.err.println("autosave debug (getUnsavedLayersFiles) file="+file);250 251 260 if (file.isFile()) { 252 System.err.println("autosave debug (getUnsavedLayersFiles) isFile");253 261 result.add(file); 254 262 } 255 263 } 256 System.err.println("autosave debug (getUnsavedLayersFiles) result="+result);257 264 return result; 258 265 } … … 271 278 } 272 279 280 /** 281 * Move file to the deleted layers directory. 282 * If moving does not work, it will try to delete the file directly. 283 * Afterwards, if the number of deleted layers gets larger than PROP_DELETED_LAYERS, 284 * some files in the deleted layers directory will be removed. 285 * 286 * @param f the file, usually from the autosave dir 287 */ 273 288 private void moveToDeletedLayersFolder(File f) { 274 System.err.println("autosave debug (moveToDeletedLayersFolder) f="+f);275 System.err.println("autosave debug (moveToDeletedLayersFolder) f.getName="+f.getName());276 277 289 File backupFile = new File(deletedLayersDir, f.getName()); 278 290 279 System.err.println("autosave debug (moveToDeletedLayersFolder) backupFile="+backupFile);280 291 if (backupFile.exists()) { 281 System.err.println("autosave debug (moveToDeletedLayersFolder) backupFile exisist"); 282 283 boolean res = deletedLayers.remove(backupFile); 284 285 System.err.println("autosave debug (moveToDeletedLayersFolder) res="+res); 286 287 boolean res2 = backupFile.delete(); 288 289 System.err.println("autosave debug (moveToDeletedLayersFolder) res2="+res2); 292 deletedLayers.remove(backupFile); 293 if (!backupFile.delete()) { 294 System.err.println(String.format("Warning: Could not delete old backup file %s", backupFile)); 295 } 290 296 } 291 297 if (f.renameTo(backupFile)) { 292 System.err.println("autosave debug (moveToDeletedLayersFolder) rename ok");293 294 298 deletedLayers.add(backupFile); 295 296 System.err.println("autosave debug (moveToDeletedLayersFolder) deletedLayers="+deletedLayers);297 299 } else { 298 300 System.err.println(String.format("Warning: Could not move autosaved file %s to %s folder", f.getName(), deletedLayersDir.getName())); 299 boolean res3 = f.delete(); 300 301 System.err.println("autosave debug (moveToDeletedLayersFolder) res3="+res3); 301 // we cannot move to deleted folder, so just try to delete it directly 302 if (!f.delete()) { 303 System.err.println(String.format("Warning: Could not delete backup file %s", f)); 304 } 302 305 } 303 306 while (deletedLayers.size() > PROP_DELETED_LAYERS.get()) { 304 307 File next = deletedLayers.remove(); 305 306 System.err.println("autosave debug (moveToDeletedLayersFolder) next="+next);307 308 boolean res4 = next.delete();309 310 System.err.println("autosave debug (moveToDeletedLayersFolder) res4="+res4);308 if (next == null) { 309 break; 310 } 311 if (!next.delete()) { 312 System.err.println(String.format("Warning: Could not delete archived backup file %s", next)); 313 } 311 314 } 312 315 } 313 316 314 317 public void dicardUnsavedLayers() { 315 List<File> ulfs = getUnsavedLayersFiles(); 316 System.err.println("autosave debug (dicardUnsavedLayers) ulfs="+ulfs); 317 for (File f: ulfs) { 318 System.err.println("autosave debug (dicardUnsavedLayers) f="+f); 318 for (File f: getUnsavedLayersFiles()) { 319 319 moveToDeletedLayersFolder(f); 320 320 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r3679 r3686 254 254 List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles(); 255 255 if (!unsavedLayerFiles.isEmpty()) { 256 System.err.println("autosave debug: unsavedLayerFiles="+unsavedLayerFiles);257 256 ExtendedDialog dialog = new ExtendedDialog( 258 257 Main.parent, … … 266 265 dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/remove"}); 267 266 int selection = dialog.showDialog().getValue(); 268 System.err.println("autosave debug: user selection="+selection);269 267 if (selection == 1) { 270 268 autosaveTask.recoverUnsavedLayers(); 271 269 } else if (selection == 3) { 272 System.err.println("autosave debug: discard autosaved layers");273 270 autosaveTask.dicardUnsavedLayers(); 274 System.err.println("autosave debug: discard autosaved layers [DONE]");275 271 } 276 272 }
Note:
See TracChangeset
for help on using the changeset viewer.