Open levitatejay opened 9 years ago
same for me
@levitatejay @goodmind can i confirm this is due to using nconf.save()
somewhere in your application? All we need to do here is use an atomic file writer module and make our own.
Yes it appears that if there is power loss within around 60 seconds of calling nconf.save()
the config file will be 0 bytes on next system start.
When my device I'm coding for (Intel Edison) crashes or loses power up to a minute after writing the config file then the entire config file is 0 bytes after a system restart and attempting to load the empty config file throws an error.
After some googling I believe this is due to the way the config file is saved... it would appear that you truncate the old file and then write the new contents... If instead the new config was written to a temporary file and then renamed it over the old file there would be the following benefits:
Taken from here: https://blogs.gnome.org/alexl/2009/03/16/ext4-vs-fsync-my-take/
This also highlights another problem... I'm not sure if its intended or not.... When attempting to load a config file that doesn't exist there is no problem and the config is simply created... If you attempt to load an empty 0 byte config file it throws an unexpected end of content error.