Changeset 3686 in josm for trunk/src/org


Ignore:
Timestamp:
2010-11-30T23:59:57+01:00 (14 years ago)
Author:
bastiK
Message:

remove debugging output for #5559; some comments

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r3679 r3686  
    3535/**
    3636 * 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.
    3750 */
    3851public class AutosaveTask extends TimerTask implements LayerChangeListener, Listener {
     
    7891
    7992            for (File f: deletedLayersDir.listFiles()) {
    80                 deletedLayers.add(f);
    81             }
    82 
     93                deletedLayers.add(f); // FIXME: sort by mtime
     94            }
    8395
    8496            timer = new Timer(true);
     
    243255        List<File> result = new ArrayList<File>();
    244256        File[] files = autosaveDir.listFiles();
    245         System.err.println("autosave debug (getUnsavedLayersFiles) files="+(files == null ? null : Arrays.toString(files)));
    246257        if (files == null)
    247258            return result;
    248259        for (File file: files) {
    249             System.err.println("autosave debug (getUnsavedLayersFiles) file="+file);
    250 
    251260            if (file.isFile()) {
    252                 System.err.println("autosave debug (getUnsavedLayersFiles) isFile");
    253261                result.add(file);
    254262            }
    255263        }
    256         System.err.println("autosave debug (getUnsavedLayersFiles) result="+result);
    257264        return result;
    258265    }
     
    271278    }
    272279
     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     */
    273288    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 
    277289        File backupFile = new File(deletedLayersDir, f.getName());
    278290
    279         System.err.println("autosave debug (moveToDeletedLayersFolder) backupFile="+backupFile);
    280291        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            }
    290296        }
    291297        if (f.renameTo(backupFile)) {
    292             System.err.println("autosave debug (moveToDeletedLayersFolder) rename ok");
    293 
    294298            deletedLayers.add(backupFile);
    295 
    296             System.err.println("autosave debug (moveToDeletedLayersFolder) deletedLayers="+deletedLayers);
    297299        } else {
    298300            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            }
    302305        }
    303306        while (deletedLayers.size() > PROP_DELETED_LAYERS.get()) {
    304307            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            }
    311314        }
    312315    }
    313316
    314317    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()) {
    319319            moveToDeletedLayersFolder(f);
    320320        }
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r3679 r3686  
    254254                    List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles();
    255255                    if (!unsavedLayerFiles.isEmpty()) {
    256                         System.err.println("autosave debug: unsavedLayerFiles="+unsavedLayerFiles);
    257256                        ExtendedDialog dialog = new ExtendedDialog(
    258257                                Main.parent,
     
    266265                        dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/remove"});
    267266                        int selection = dialog.showDialog().getValue();
    268                         System.err.println("autosave debug: user selection="+selection);
    269267                        if (selection == 1) {
    270268                            autosaveTask.recoverUnsavedLayers();
    271269                        } else if (selection == 3) {
    272                             System.err.println("autosave debug: discard autosaved layers");
    273270                            autosaveTask.dicardUnsavedLayers();
    274                             System.err.println("autosave debug: discard autosaved layers [DONE]");
    275271                        }
    276272                    }
Note: See TracChangeset for help on using the changeset viewer.