Modify

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#17350 closed defect (fixed)

[Patch] Autosave makes JOSM think layer is saved

Reported by: ShadowFoxNixill Owned by: team
Priority: normal Milestone: 19.10
Component: Core Version:
Keywords: template_report autosave Cc:

Description

What steps will reproduce the problem?

  1. Open a map from an existing file (make sure "Discourage upload" is turned on)
  2. Make some modifications
  3. Wait for JOSM to autosave

What is the expected result?

JOSM should act as if the file hasn't been saved, as it actually hasn't (the autosave goes to a backup file). This means:
Title bar: Should display an asterisk
Attempting to close JOSM or remove the layer: Should prompt you to save the layer first

What happens instead?

JOSM acts as if a regular save to the file being modified has occurred, meaning:
Title bar: Doesn't display an asterisk
Attempting to close JOSM or remove the layer: Does so without any prompt

Please provide any additional information below. Attach a screenshot if possible.

URL:https://josm.openstreetmap.de/svn/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2019-02-15 20:59:09 +0100 (Fri, 15 Feb 2019)
Build-Date:2019-02-16 02:30:55
Revision:14790
Relative:URL: ^/trunk

Identification: JOSM/1.5 (14790 en) Windows 10 64-Bit
OS Build number: Windows 10 Education 1803 (17134)
Memory Usage: 1997 MB / 1997 MB (869 MB allocated, but free)
Java version: 1.8.0_201-b09, Oracle Corporation, Java HotSpot(TM) 64-Bit Server VM
Screen: \Display0 1920x1080, \Display1 1920x1080
Maximum Screen Size: 1920x1080
VM arguments: [-Djava.security.manager, -Djava.security.policy=file:<java.home>\lib\security\javaws.policy, -DtrustProxy=true, -Djnlpx.home=<java.home>\bin, -Djnlpx.origFilenameArg=%UserProfile%\Programs\josm-latest.jnlp, -Djnlpx.remove=false, -Djava.util.Arrays.useLegacyMergeSort=true, -Djnlpx.heapsize=NULL,2048m, -Djnlpx.splashport=62966, -Djnlpx.jvm=<java.home>\bin\javaw.exe]
Dataset consistency test: No problems found

Plugins:
+ apache-commons (34506)
+ continuosDownload (82)
+ ejml (34389)
+ geotools (34513)
+ jaxb (34678)
+ jts (34524)
+ opendata (34867)
+ pbf (34867)
+ utilsplugin2 (34867)

Map paint styles:
+ https://github.com/bastik/mapcss-tools/raw/osm/mapnik2mapcss/osm-results/mapnik.zip

Last errors/warnings:
- W: java.io.IOException: Attribution is not loaded yet
- W: java.io.IOException: Attribution is not loaded yet
- W: java.io.IOException: Attribution is not loaded yet
- W: java.io.IOException: Attribution is not loaded yet
- W: java.io.IOException: Tags to paste are not valid.
- W: java.io.IOException: Tags to paste are not valid.
- W: JOSM expected to find primitive [way 42372917] in dataset but it is not there. Please report this at https://josm.openstreetmap.de. This is not a critical error, it should be safe to continue in your work.
- E: java.lang.Exception
- W: JOSM expected to find primitive [way 42372917] in dataset but it is not there. Please report this at https://josm.openstreetmap.de. This is not a critical error, it should be safe to continue in your work.
- E: java.lang.Exception

Attachments (0)

Change History (8)

comment:1 by Don-vip, 6 years ago

Keywords: autosave added

comment:2 by Klumbumbus, 6 years ago

If I remeber corrctly this is not related to autosave. JOSM never checks for changes in layers with upload=no (which should be changed in my opinion. There should already be a ticket for this somewhere.)

comment:3 by Don-vip, 5 years ago

Ticket #18244 has been marked as a duplicate of this ticket.

comment:4 by mdk, 5 years ago

If you load a layer from file with upload=never, the File.Save Menu will be enabled on changes and disabled, if you save the file. But when AutoSave saves the layer (in the "AutoSave" folder, also the "Save" will be disabled for the original file location. You can only save with Save As... and hopefully override the correct file or you loose the changes in the original file on closing the layer / ending JOSM because no warning about unsaved data occur. I lost may edits in files because I closed JOSM and did not remember to manually save the changes in that layer!

I see three different locations to "persist" a layer: Upload, File and AutoSave. Each needs to track separately where are unsaved changes. But AutoSave should never mark the normal File as saved!

Steps to reproduce:

  • Reduce AutoSave interval to 30 seconds.
  • load any file -> File.Save is disabled (OK)
  • do any modification -> File.Save is enabled (OK)
  • Open File Menu and wait - after a wile File.Save will be disabled without any interaction of the user. (not ok)

comment:5 by Bjoeni, 5 years ago

Summary: Autosave makes JOSM think layer is saved[Patch] Autosave makes JOSM think layer is saved

The onPostSaveToFile event shouldn't be fired on autosave since it didn't actually save (at least not in a way the layer would expect when this event is fired).

@mdk, quoting from the other ticket:

Without knowing the code I assume, that there are two modified flags for each layer: one for upload and one for saving as file. Both flags are set on any modification, but the file_modified flag is cleaed on save and the upload_modified flag is cleared an upload.

AutosaveTask keeps track of the changes itself (Set<DataSet> changedDatasets, filled by listening to processDatasetEvent), so we don't even need a third flag. But other than that, yes the problem is that the flag requiresSaveToFile is reset on autosave (because of the misleading event).

@Don-vip:

  • src/org/openstreetmap/josm/gui/io/importexport/OsmExporter.java

     
    6565     * Exports OSM data to the given file.
    6666     * @param file Output file
    6767     * @param layer Data layer. Must be an instance of {@link OsmDataLayer}.
    68      * @param noBackup if {@code true}, the potential backup file created if the output file already exists will be deleted
    69      *                 after a successful export
     68     * @param isAutosave if {@code true}, the potential backup file created if the output file already exists will be deleted
     69     *                   after a successful export and post-save events won't be fired
    7070     * @throws IOException in case of IO errors
    7171     * @throws InvalidPathException when file name cannot be converted into a Path
    7272     * @throws IllegalArgumentException if {@code layer} is not an instance of {@code OsmDataLayer}
    7373     */
    74     public void exportData(File file, Layer layer, boolean noBackup) throws IOException {
     74    public void exportData(File file, Layer layer, boolean isAutosave) throws IOException {
    7575        if (!(layer instanceof OsmDataLayer)) {
    7676            throw new IllegalArgumentException(
    7777                    MessageFormat.format("Expected instance of OsmDataLayer. Got ''{0}''.", layer.getClass().getName()));
    7878        }
    79         save(file, (OsmDataLayer) layer, noBackup);
     79        save(file, (OsmDataLayer) layer, isAutosave);
    8080    }
    8181
    8282    protected static OutputStream getOutputStream(File file) throws IOException {
     
    8383        return Compression.getCompressedFileOutputStream(file);
    8484    }
    8585
    86     private void save(File file, OsmDataLayer layer, boolean noBackup) throws IOException {
     86    private void save(File file, OsmDataLayer layer, boolean isAutosave) throws IOException {
    8787        File tmpFile = null;
    8888        try {
    8989            if (file.exists() && !file.canWrite()) {
     
    9898            }
    9999
    100100            doSave(file, layer);
    101             if ((noBackup || !Config.getPref().getBoolean("save.keepbackup", false)) && tmpFile != null) {
     101            if ((isAutosave || !Config.getPref().getBoolean("save.keepbackup", false)) && tmpFile != null) {
    102102                Utils.deleteFile(tmpFile);
    103103            }
    104             layer.onPostSaveToFile();
     104            if (!isAutosave) {
     105                layer.onPostSaveToFile();
     106            }
    105107        } catch (IOException | InvalidPathException e) {
    106108            Logging.error(e);

comment:6 by Don-vip, 5 years ago

Milestone: 19.10

comment:7 by Don-vip, 5 years ago

Resolution: fixed
Status: newclosed

In 15474/josm:

fix #17350 - don't fire post-save event when autosaving a file (patch by Bjoeni)

comment:8 by Don-vip, 5 years ago

Thanks!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.