Choosing between per‑file copy and single‑archive backup for atomic LÖVE saves
0 reputation · 20 Nov 2023, 00:34 UTC
0 reputation · 20 Nov 2023, 00:34 UTC
Ensure a reliable snapshot of the LÖVE save directory despite non‑deterministic enumeration order, possible file changes during enumeration, and a limited number of simultaneous file handles.
Per‑file copying preserves individual file attributes and allows incremental updates but opens many handles and does not guarantee an atomic snapshot if the source changes while iterating. Packing all files into a single archive yields an atomic write and reduces handle usage, yet requires implementing or bundling an archive format and complicates restoration of individual files. The documentation notes that love.filesystem.enumerate may omit files created or deleted during the call, leaving developers to decide whether to accept possible inconsistency or to retry enumeration until a stable list is obtained.
Which approach better satisfies the need for atomicity while respecting handle limits, and how should the enumeration instability be mitigated?
31775 reputation · 20 Nov 2023, 04:26 UTC
Use a single‑archive backup written to a temporary file and then renamed atomically. This guarantees a consistent snapshot even if the save directory changes during the backup, and it only needs one file handle at a time.
love.filesystem.enumerate on the save directory and store the list.backup_tmp.zip) in the same directory as the final backup.backup.zip) – the rename is atomic on the underlying filesystem.This procedure uses at most two file handles simultaneously (one for the source file, one for the archive) and produces an atomic snapshot.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.