MarcusWolschon / osmeditor4android

Vespucci is a OpenStreetMap editor for Android

Home Page:http://vespucci.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overwiriting a JOSM or OSC file does not truncate existing file

kidhanis opened this issue · comments

Vespucci Version

19.3.4.0

Download source

F-Droid

Device (Manufacturer and Model)

Samsung Galaxy S10e

Android Version

11

Behaviour/Symptoms

Some files that were saved with Transfer -> File -> Save to JOSM file can't be read back. Same issue with files saved with Transfer -> File -> Export changes to OSC file.

Expected Behaviour

Files should be read without any issues

How to recreate

Example with JOSM file

  1. Clear OSM data with Transfer -> Clear data, if data is present. This step isn't necessary, but the rest of the description assumes data was cleared.
  2. Save a file using Transfer -> File -> Save to JOSM file.
  3. Open file in a text editor. In my case, the file has 104 bytes and looks like
<?xml version='1.0' encoding='UTF-8' ?><osm generator="Vespucci/19.3.4.0" version="0.6" upload="true" />
  1. Add bytes to the file with the text editor. In my file, I changed version='1.0' to version='1.00'. Save to same file. Size of my file is now 105 bytes.
  2. Back in Vespucci, again Save to JOSM file, and choose the same file. When saving, the file manager asks to overwrite, so accept to overwrite. Size is still 105 bytes.
  3. Try to read file with Transfer -> File -> Read from JOSM file, but an error pops up:

Invalid data read
Please consult the documentation on supported file formats and required data fields.

At line 1, column 104: junk after document element

Crash dump submitted (no or yes + date)

No crash dump

Any other potentially relevant information

The file after step 5 looks like

<?xml version='1.0' encoding='UTF-8' ?><osm generator="Vespucci/19.3.4.0" version="0.6" upload="true" />>

It has the same content from step 3 but with an extra character '>' at the end.
Warnings may vary based on the number of bytes added in step 4, but the outcome is the same.

Same behavior using Safe mode on the app. Behavior verified on another Samsung device with a freshly installed app running Android 13.

However, the behavior is correct on an ASUS device running Marshmallow, where step 6 results in successfully reading the file, but on this device the file manager writes to file without asking for permission to overwrite in step 5.

I suspect there are (at least) two things going on here:

  • if you save empty data you can't read that back in Vespucci because requisite elements are missing, for example bounding boxes. This is an edge case that can't be easily fixed. Just saving and re-reading files with content to the Vespucci directory works just as expected in my testing here (actually it will read it, but still complain).

  • you are assuming UNIX semantics for file system permissions/access, which however is no longer the case since Android 10. You didn't mention where you are saving the files and from where you are reading them? And which editor are you using?

On Android 10 and later apps do not have access to files owned by other apps except in very limited circumstances. The old access to external files permission essentially doesn't do anything any more.

We don't support files in the Document folder and it is unclear what exactly happens with 'shared' files there to start with.

Further reading: https://www.openstreetmap.org/user/SimonPoole/diary/156819

But at least with that information we might be abke to suggest a workaround.

Note the issue with the wrong modal being displayed was fixed here: 10640a7

So it seems as if the non-truncating aspect of the behaviour is simply an Android bug see https://issuetracker.google.com/issues/180526528