Hello,
is it possible that the app’s execution gets interrupted/terminated when writing to a file, like in the follow example:
-- Data (string) to write local saveData = "My app state data" -- Path for the file to write local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory ) -- Open the file handle local file, errorString = io.open( path, "w" ) --------[[INTERRUPTION/TERMINATION BETWEEN HERE]]--------- if not file then -- Error occurred; output the cause print( "File error: " .. errorString ) else -- Write data to file file:write( saveData ) ------------------[[AND HERE]]----------------- -- Close the file handle io.close( file ) end file = nil
Because I noticed that the file gets erased just with the io.open( path, “w” ).
So if the app gets terminated before writing the content and closing the file, the data would be lost.
I know that probability is quite low, but is it technically possible? And if yes, is there a way to avoid this problem?
Best regards!