pkg/fs/README.md
Last Updated: November 25, 2025
pkg/fs provides safe, cross-platform filesystem helpers used across PhotoPrism. It supplies permission constants, copy/move utilities with force-aware semantics, safe path joins, archive extraction with size limits, MIME and extension lookups, hashing, canonical path casing, and fast directory walking with ignore lists.
internal/*.ModeDir, ModeFile, ModeConfigFile, ModeSecretFile, ModeBackupFile).force, unsafe zip extraction)..ppstorage markers.mode.go, filepath.go, canonical.go, case.go.copy_move.go, write.go, cache.go, purge.go.zip.go (size limits, safe join), tests in zip_test.go.file_type*.go, mime.go, file_ext*.go, name.go.hash.go, id.go.walk.go, ignore.go, done.go.bytes.go, resolve.go, symlink.go, modtime.go, readlines.go.force=true only when the caller explicitly confirmed replacement; empty files may be replaced without force.io/fs bits.fileSizeLimit / totalSizeLimit in Unzip for untrusted inputs; ensure tests cover path traversal and size caps (see zip_test.go).go test ./pkg/fs -run 'Copy|Move|Unzip|Write' -count=1 keeps feedback quick; full package: go test ./pkg/fs -count=1.safeJoin: normalize \\//, use filepath.Rel to reject paths escaping baseDir, and keep volume/absolute checks.Unzip and treat totalSizeLimit=0 as “no limit” while documenting -1 as unlimited.io.CopyBuffer in Copy, Hash, Checksum, WriteFileFromReader to cut allocations/GC.