Skip to content

File corruption when overwriting files in export #61

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

Closed
v-kawade opened this issue May 9, 2025 · 8 comments
Closed

File corruption when overwriting files in export #61

v-kawade opened this issue May 9, 2025 · 8 comments

Comments

@v-kawade
Copy link

v-kawade commented May 9, 2025

If NativeFilePicker.ExportFile() overwrites an existing file (XML) with contents of a smaller size, the contents of the existing file will remain and the file will be corrupted.

  • Unity version: 6000.1.2f1
  • Platform: Android
  • Device: 'Xiaomi Pad 6' and 'Xperia 5II'
  • How did you download the plugin: Asset Store (v1.4.0)
@yasirkula
Copy link
Owner

If original XML (A) was 50 KB and the new XML (B) is 20 KB, is the resulting XML 70 KB (A+B) or the first 20 KB of A is replaced with B while the remaining 30 KB of A remain the same (i.e. a 50 KB output)?

@v-kawade
Copy link
Author

Hi, thanks,

  • The original XML (A) was 6,153 Bytes.
  • The new XML (B) is 4,011 Bytes.
  • The resulting XML is first 4,011 Bytes of A is replaced with B while the remaining 2,142 Bytes of A remain the same.

@yasirkula yasirkula transferred this issue from yasirkula/UnityNativeGallery May 16, 2025
@yasirkula
Copy link
Owner

I've found out that this is a common problem:

I think this is a stupid default behaviour. Thank you for bringing this to my attention. I'll hopefully release a fix in a couple of days.

@yasirkula
Copy link
Owner

Please let me know if the issue persists in v1.4.1.

@v-kawade
Copy link
Author

Thanks. I have confirmed that the problem has been resolved in v1.4.1.
For reference, when overwriting an existing file, the 'Xiaomi Pad 6' no longer confirms the overwrite and the file name now ends with a (1) or something similar.
'Xperia 5II' has the same overwrite confirmation as before and exports correctly with the original file name.

@yasirkula
Copy link
Owner

This change shouldn't affect the overwrite dialog because the changed code takes place after the overwrite dialog.

@v-kawade
Copy link
Author

'Xiaomi Pad 6', when calling ExportFile() with an existing file name, (1) was given without confirmation if the file browser did nothing and OK, and there was an overwrite confirmation when the same file name was selected in the file browser.
I see. This behavior seems to have been the case originally.

@yasirkula
Copy link
Owner

I think this behaviour depends on the device vendor: 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.

For example, if your app tries to save a file called confirmation.pdf in a directory that already has a file with that name, the system saves the new file with the name confirmation(1).pdf.

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

No branches or pull requests

2 participants