3 ms·
Most app file formats do not have the same reliability testing level as filesystems. Filesystems need years of use by brave people before they're considered OK
by barrkel 13y ago
Most app file formats do not have the same reliability testing level as filesystems. Filesystems need years of use by brave people before they're considered OK for production.
If you're updating files in place without a whole rewrite, then you are effectively writing a filesystem.
I prefer to use a different approach where possible: write a diff log, and occasionally do a rewrite of the whole file.
When you do have to treat the on-disk file as a filesystem, I'd explicitly treat it as such. Have a low-level structure that does not need modification for different versions, is portable and highly tested. Do application-level structure with normal read-modify-write, but layered on top of the virtual filesystem layer. Consider having two modes, one where the virtual filesystem just proxies the real filesystem, and instead of a "file", you have a directory structure on disk. Consider using an existing component for this (zip archive libraries are popular, but not particularly efficient for writing).
Mmap does make the problem worse. It encourages you to be lazy towards versioning and portability.