Programming Tips - Programming: Best practices when updating a shared .ini file
Date: 2014dec9
Update: 2025aug5
Q. Programming: Best practices when updating a shared .ini file
A.
1. Make sure all updates to the thefile.ini file are done atomically.
ie write to a temp name like thefile.ini.a_tmp_suffix and rename to thefile.ini.
1B. Do not use thefile.ini.new as the temp name because somebody else might
use that. Use the name of the updating app in the temp name.
eg thefile.ini.app1_new or thefile.ini.app2_new
2. Apps which update the .ini file should not delete or change
fields/sections they don't know about.
Unknown fields and sections should be preserved during updates.
3. These guidelines apply to any shred text file - .xml or .json
In summary:
- Read in the the .ini file preserving everything
- Make the update in memory
- Write it out to thefile.ini.theapp_new
- Rename to thefile.ini