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

[Android] writeFile not overwriting existing file #46

Closed
Eralyne opened this issue May 28, 2024 · 6 comments
Closed

[Android] writeFile not overwriting existing file #46

Eralyne opened this issue May 28, 2024 · 6 comments
Labels
P4 Perhaps no action needed.

Comments

@Eralyne
Copy link

Eralyne commented May 28, 2024

It appears that the issue presented in the original RNFS is still present in this new fork.

I'm trying to overwrite files by writing to the same file name in the same directory and it works perfectly fine on iOS but it doesn't on Android, which is reflective of how it is in the current RNFS.

I'm mainly wondering if this is something that you intend to keep as is or if it's a genuine issue that wasn't addressed yet.

@birdofpreyru birdofpreyru added the P1 High priority issue. label May 28, 2024
@birdofpreyru
Copy link
Owner

Thanks @Eralyne , I did not know about this issue. writeFile() is important to me (#26), thus I'll try to test and fix it rather sooner than later.

@birdofpreyru
Copy link
Owner

Hey @Eralyne , I just tried to reproduce the bug within this library's Example App, by inserting await writeFile(path, 'existing file content', 'ascii'); prior to the line 842 here:

'readFile() and writeFile()': async () => {
const good = 'GÖÖÐ\n';
const utf8 = '\x47\xC3\x96\xC3\x96\xC3\x90\x0A';
const path = `${TemporaryDirectoryPath}/test-file`;
try {
await writeFile(path, utf8, 'ascii');
let res = await readFile(path);
if (res !== good) return 'fail';
res = await readFile(path, 'ascii');
if (res !== utf8) return 'fail';
await writeFile(path, good);
res = await readFile(path);
if (res !== good) return 'fail';
return 'pass';
} catch (e) {
return 'fail';
}
},

expecting that if there is a problem with over-writing existing files by writeFile() the follow-up readFile() calls in that test will read unexpected content and fail the test; however, it does not fail for me, the test seems to pass fine. Tested in Emulator with both the latest Android 14 (SDK 34), and Android 10 (Q, SDK 29), which was mentioned in the original ticket.

Will you double-check me please? Am I missing something with my test, or with the Android version on which it should fail?

@birdofpreyru
Copy link
Owner

Here is a dedicated branch with already updated test — https://github.com/birdofpreyru/react-native-fs/tree/issue/46.

@Eralyne
Copy link
Author

Eralyne commented Jun 12, 2024

I'll double-check when I get the chance, that's interesting that it's not failing.

@Eralyne
Copy link
Author

Eralyne commented Jun 20, 2024

Hmm, I can't replicate it either. In our scenario, we're writing images as base64 to the directory. I tried doing that in your example code and it still seems to be working fine with that situation as well.

I'm going to go back to our codebase and see if I can adjust a few things to see if I can isolate the issue better. The weird thing is how closely it resembles the issue I linked originally.

I'll send an update here as soon as I find something. It's a high priority on our end.

@birdofpreyru birdofpreyru added the On Hold Blocked for some reason. label Jun 20, 2024
@Eralyne
Copy link
Author

Eralyne commented Jun 24, 2024

Looks like the overwrite is working fine. Our image is being cached by Android in a different way than iOS wherein it's not being refreshed when we need it to be.

Thanks for taking a look at this for us, sorry for wasting your time with a non-issue haha

@birdofpreyru birdofpreyru added P4 Perhaps no action needed. and removed P1 High priority issue. On Hold Blocked for some reason. labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 Perhaps no action needed.
Projects
None yet
Development

No branches or pull requests

2 participants