Documentation
¶
Overview ¶
Package fsutil holds small cross-cutting filesystem helpers shared across the bridge — today the durability barrier (file + parent-dir fsync) that producers of on-disk sidecars run before committing the SQLite row that points at the freshly-written file.
`internal/transcode` carries an equivalent unexported copy (`fsyncFileAndParent` / `syncDir`) predating this package; keep the two in lockstep until that one is migrated over.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FsyncFileAndParent ¶
FsyncFileAndParent flushes `path` (and, on POSIX, its parent directory entry) to stable storage. Producers call this on a freshly-renamed sidecar BEFORE committing the DB row that points at it, so a client reacting to the commit (e.g. an iOS delta-sync) can never race a non-durable file. The inverse ordering (commit then fsync) recovers cleanly — a crash in the gap just re-runs the producer — but a missing-file race after a published commit does not.
func SanitiseForFAT ¶
SanitiseForFAT replaces characters that FAT-family filesystems (FAT32 / exFAT / NTFS) reject in filenames with `_`, deterministically (so re-runs of the same source produce identical output — DB sidecar- path lookups depend on it). Operates on a single path SEGMENT (basename); forward slash isn't included because the caller has already split the path. Backslash IS included (cross-OS rip tools sometimes embed it in one segment).
Lazy allocation: a clean basename (>95% of a typical library) is returned unchanged with zero allocations; only the first illegal byte materialises a mutable copy. The bad set is all ASCII, so the byte loop is safe on UTF-8 input (multi-byte runes start ≥ 0x80 and never collide with the ASCII bad chars).
func TrimPartialTrailingRune ¶
TrimPartialTrailingRune removes at most utf8.UTFMax-1 trailing bytes when a byte-slice cut split a multi-byte rune, in O(1). A string that still ends with genuinely invalid bytes after that is returned as-is (interior garbage is left for the JSON encoder to render as U+FFFD). Used when truncating subprocess stderr at a fixed byte budget.
func TruncateUTF8AtMost ¶
TruncateUTF8AtMost returns the longest prefix of s whose byte length is ≤ maxBytes, ending on a rune boundary (never slices mid-rune).
func TruncateUTF8FromEnd ¶
TruncateUTF8FromEnd returns the longest suffix of s whose byte length is ≤ maxBytes, starting on a rune boundary.
Types ¶
This section is empty.