deyles-zz / sculejs

SculeJS - data structures for the web
165 stars 24 forks source link

Database gets corrupted if interrupted in the middle of write #50

Closed jkryl closed 9 years ago

jkryl commented 9 years ago

I started to see frequent db corruptions because of previous unclean shutdown and yet the problem is easy to solve at least for the nodejs backend. Contents can be written to temporary file and when the write is done, the temp file can be moved to final destination (rename is atomic at least on unix(like) OSes). I have a fix but I can't submit a pull request until issue #23 is fixed as the fix assumes standard conventions for async callbacks to be followed by the code (first param in callback is error followed by arguments etc.) and changing write and read methods for all storage backends to follow proper rules is a bit out of scope for me now...

deyles-zz commented 9 years ago

Hey Jan, I've committed a fix for this issue. SculeJS will now write collections to a temporary file before performing a rename to replace the existing file. This fix will be available in version 0.1.4.