fsutil

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 4 Imported by: 0

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

func FsyncFileAndParent(path string) error

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

func SanitiseForFAT(s string) string

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

func TrimPartialTrailingRune(s string) string

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

func TruncateUTF8AtMost(s string, maxBytes int) string

TruncateUTF8AtMost returns the longest prefix of s whose byte length is ≤ maxBytes, ending on a rune boundary (never slices mid-rune).

func TruncateUTF8FromEnd

func TruncateUTF8FromEnd(s string, maxBytes int) string

TruncateUTF8FromEnd returns the longest suffix of s whose byte length is ≤ maxBytes, starting on a rune boundary.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL