Bug 506039 - Exporting on Android can end up with a useless filename
Summary: Exporting on Android can end up with a useless filename
Status: RESOLVED UPSTREAM
Alias: None
Product: krita
Classification: Applications
Component: File formats (other bugs)
Version First Reported In: 5.2.9
Platform: Android Android 14.x
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-23 12:37 UTC by Tiar
Modified: 2025-11-07 07:39 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
screenshot-overwrite-dialog (72.55 KB, image/png)
2025-07-03 04:32 UTC, sh_zam
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tiar 2025-06-23 12:37:28 UTC
SUMMARY
If you try to export to the same file again, Krita will save it as "filename.png (n)" instead of "filename(n).png" or any other reasonable filename. Krita can open it later, but the Samsung Gallery app doesn't, since from its perspective the file extension is wrong.

Same happens with .kra files and probably any other file type, it's just if it's Krita's own, it doesn't matter since Krita can just open it regardless.

STEPS TO REPRODUCE
1. Create a file.
2. Export to "file.png"
3. Export to "file.png" again.

OBSERVED RESULT
A file called "file.png (1)" in the folder besides "file.png".
Standard system gallery app cannot open it and the file system app calls the file type "BIN" instead of "PNG".

EXPECTED RESULT
A question whether I want to overwrite, and if yes, it should save into the same file.


SOFTWARE/OS VERSIONS
Android: 14.0
Qt Version: 5.x
Comment 1 sh_zam 2025-07-03 04:32:13 UTC
Created attachment 182883 [details]
screenshot-overwrite-dialog

Oddly if you Create a new file and then Save it it *can* overwrite it. So maybe we are not setting the flags correctly...
Comment 2 dra.w.p.il.e+bugskde 2025-11-07 07:39:01 UTC
I looked into this. The reason it doesn't work is because Qt uses ACTION_CREATE_DOCUMENT to save files. To quote https://developer.android.com/training/data-storage/shared/documents-files#create-file

> Note: ACTION_CREATE_DOCUMENT cannot overwrite an existing file. If your app tries to save a file with the same name, the system appends a number in parentheses at the end of the file name.

The alternative would be to use ACTION_OPEN_DOCUMENT_TREE, but that doesn't support a bunch of other stuff. For example, the the user can't save to a bunch of directories, such as the downloads directory, instead being told that they can't choose that directory to "protect their privacy". They can also no longer save to other storage providers, such as Google Drive, since they aren't directories. Which is probably more important than the ability to overwrite files.

So I don't think there's a sensible fix for this on Krita's side, it's just yet another case where the Android file system is bad and we need to implement an entirely different concept of saving images on Android instead, cf. https://invent.kde.org/graphics/krita/-/issues/20