Documentation
¶
Overview ¶
Package savefile provides core-free atomic file staging, backup rotation, directory syncing, stale temporary-file cleanup, and portable filename validation shared by pkg/save and pkg/online/gameserver.
Index ¶
- Constants
- func DirSyncUnsupported(err error) bool
- func SweepStaleTemps(dir string)
- func SyncDir(dir string) error
- func ValidateName(name string) error
- func WriteAtomic(dir, target string, data []byte) error
- func WriteStaged(dir, primary string, data []byte, beforeRename func() error) error
- func WriteTemp(dir string, data []byte) (string, error)
- func WriteWithBackup(dir, primary, backup string, data []byte, valid func([]byte) bool) error
Constants ¶
const StaleTempAge = time.Hour
StaleTempAge is how old a .save-*.tmp file must be before SweepStaleTemps treats it as left behind by an interrupted write rather than one in progress.
Variables ¶
This section is empty.
Functions ¶
func DirSyncUnsupported ¶
DirSyncUnsupported reports whether err from syncing a directory means the file system does not support it rather than that it failed.
func SweepStaleTemps ¶
func SweepStaleTemps(dir string)
SweepStaleTemps removes .save-*.tmp staging files older than StaleTempAge. Errors are ignored: a file that cannot be removed now is tried again later.
func SyncDir ¶
SyncDir flushes directory metadata after a rename or removal so the change survives a crash. Windows cannot sync a directory handle and needs no separate sync for renames, so it is skipped there; anywhere else a failure is returned, except that a file system that cannot sync a directory at all (EINVAL or ENOTSUP, as on some network and FUSE mounts) is treated as having nothing to sync.
func ValidateName ¶
ValidateName rejects empty names, overly long names, path separators, traversal sequences, leading or trailing dots or spaces, control characters, and Windows-reserved filenames.
func WriteAtomic ¶
WriteAtomic writes data to target inside dir by staging a synced temporary file, renaming it over target, and syncing dir.
func WriteStaged ¶
WriteStaged stages data into a synced temporary file in dir, runs beforeRename (if non-nil) before touching primary, atomically renames the temporary file over primary, and syncs dir. If staging, beforeRename, or rename fails, the staged temporary file is removed and primary is unchanged.
func WriteTemp ¶
WriteTemp writes data to a new temporary file in dir, syncs it to disk and closes it, returning its path.
func WriteWithBackup ¶
WriteWithBackup stages data in dir, preserves any existing primary that passes valid (or any existing primary when valid is nil) in backup via WriteAtomic, renames the staged file over primary, and syncs dir.
Types ¶
This section is empty.