Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1769 export overwrite existing files #1771

Merged
merged 1 commit into from
Nov 28, 2023
Merged

Conversation

pstorch
Copy link
Member

@pstorch pstorch commented Nov 27, 2023

Found the cause of the broken .gpx exports.
As the tracks were duplicates (from test ex- and imports). The export all function wrote two times to the same file. The second time the content was slightly less bytes, so the first file was only partly overwritten resulting in a broken xml file.

We need to make sure the target file is properly overwritten (truncated at the beginning).

Solution:
https://stackoverflow.com/questions/56902845/how-to-properly-overwrite-content-of-file-using-android-storage-access-framework

@dennisguse do we have to do anything else if two tracks result in the same filename and overwriting each other while exporting?

@dennisguse
Copy link
Member

We could also use this (same link), right?

contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
    // Write to outputStream
}

@pstorch
Copy link
Member Author

pstorch commented Nov 28, 2023

We could also use this (same link), right?

contentResolver.openOutputStream(uri, "wt")?.use { outputStream ->
    // Write to outputStream
}

Looks like Kotlin

@dennisguse
Copy link
Member

It is but the "wt" should work in Java as well ;)

@pstorch
Copy link
Member Author

pstorch commented Nov 28, 2023

Ah, I'll try

@pstorch pstorch force-pushed the fix_export_file_overwrite branch from def1263 to 5215f5c Compare November 28, 2023 19:14
@pstorch pstorch force-pushed the fix_export_file_overwrite branch from 5215f5c to dfd5b56 Compare November 28, 2023 19:14
@pstorch
Copy link
Member Author

pstorch commented Nov 28, 2023

Yes, the simple solution works, too. Thanks for the hint.

@dennisguse dennisguse merged commit 87d7ebc into main Nov 28, 2023
3 of 5 checks passed
@dennisguse dennisguse deleted the fix_export_file_overwrite branch November 28, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants