in reply to Re: Yet another config file editing programme : Tell me how to make it better !
in thread Yet another config file editing programme : Tell me how to make it better !

There is a very small, but finite risk of the Pi being turned off in the middle of a file write
Ha ha, I have long experience contemplating this annoying and tricky problem! The straightforward solution I concocted back in 2003 (and am still happy with) is to simply write a new file on the same file system ... and then use (atomic) rename to clobber the original file - but only after the new file has been successfully written. This is described in detail at:

  • Comment on Re^2: Yet another config file editing programme : Tell me how to make it better !

Replies are listed 'Best First'.
Re^3: Yet another config file editing programme : Tell me how to make it better !
by tybalt89 (Monsignor) on Sep 03, 2021 at 09:32 UTC

    See ->spew (and ->edit and ->edit_lines) in Path::Tiny

      From Path::Tiny's doco of its excellently named spew method: "The file is written to a temporary file in the same directory, then renamed over the original.". Hey, xdg stole my idea! Seriously, it looks like an excellent module, I should start using it ... especially given my old golfing buddy endorses it. :)

      Hi
      I am going to use Path::Tiny.

      Dazz