cordova-promise-fs icon indicating copy to clipboard operation
cordova-promise-fs copied to clipboard

concurrent writes and file corruption on iOS

Open DjulLau opened this issue 7 years ago • 0 comments

Hi,

Not sure if this is related to this particular module (maybe a lower level problem) but I'm experiencing file corruption on iOS.

I'm using fs.write() to replace the whole content of a file as a way to save data. The function maybe called several times in a short period and no particular "waiting for previous write" mechanism has been implemented. This is working perfectly well on Android but on iOS I sometime get a corrupted file with the whole content plus part off the content after, like if a write appended part of the data instead of replacing it. Of course this ends in data corruption as the JSON content cannot be parsed anymore :( I've tried to fs.remove() the file before fs.write() but fs.remove() sometimes fails (with Error code 1 even if mustExists is false)...

Questions:

  • Is it safe to call several fs.write() on the same file ?
  • If not what can I do the work around this problem ?

Thanks a lot,

Julien

DjulLau avatar Oct 05 '17 13:10 DjulLau