inaitana opened a new issue, #571:
URL: https://github.com/apache/cordova-plugin-file/issues/571

   # Feature Request
   
   ## Motivation Behind Feature
   I run a distributed ticketing app on a few Android devices, some of which 
have a built-in printer.
   All the app persistence (sessions and tickets) is managed through files.
   After years of cluelessly watching random episodes data loss, I finally 
tracked down a major issue.
   
   For each new ticket, I overwrite files with a FileWriter (I actually use 
Ionic with Awesome Cordova's File plugin, but this is irrelevant here).
   In this moment, with adb I can even watch the files content get seemingly 
updated, and read the new content with cat.
   After the writing callback, the app prints the ticket, and this is my point 
of failure: printing generates a power consumption peak, and devices on old 
batteries might shut off abruptly.
   When the device reboots after the unmanaged shutdown, recently written files 
are empty. Not outdated, just empty, 0 bytes.
   
   I know that async writing is an OS feature (and Android volumes are always 
mounted async as far as I know), so the plugin does work as expected, but I 
think there can be more.
   
   ## Feature Description
   Android actually offers a 
[sync](https://developer.android.com/reference/java/io/FileDescriptor#sync()) 
method on FileDescriptor since API level 1, which can be used to ensure sync 
writing.
   I implemented support for it in LocalFilesystem.java, and introduced a 
setSync method in FileWriter.js to set an optional flag to ensure sync writes.
   I am currently testing my solution, will start deploying it in production 
next week, and if it works as expected I will file a PR and add a reference 
here.
   
   ## Alternatives or Workarounds
   Again, I know async writing is basically default.
   But I believe, if this feature won't be implemented, the documentation 
should at least warn about potential problems.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to