fileutils

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fileutils provides file operation utilities including atomic writes.

Package fileutils provides file operation utilities including atomic writes and path validation for security.

Index

Constants

View Source
const (
	// DefaultLockTimeout is the maximum time to wait for a file lock.
	DefaultLockTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(targetPath string, data []byte, perm os.FileMode) error

AtomicWriteFile writes data to a file atomically by writing to a temporary file and then renaming it. This ensures that readers either see the complete old file or the complete new file, never a partially written file.

func ValidateWorkloadNameForPath

func ValidateWorkloadNameForPath(workloadName string) error

ValidateWorkloadNameForPath validates a workload name to prevent path traversal attacks. It ensures the name is safe for use in file path construction by checking: - Path traversal patterns (..) - Absolute paths - Path separators (/, \) - Command injection patterns - Null bytes - Invalid characters (only alphanumeric, dots, hyphens, underscores allowed) - Length limits

This function delegates to types.ValidateWorkloadName which performs comprehensive validation including filepath.Clean normalization and filepath.Rel path traversal checks.

Returns nil if the workload name is safe for path construction, or an error describing the validation failure.

func WithFileLock added in v0.11.1

func WithFileLock(path string, fn func() error) error

WithFileLock executes fn while holding an OS-level advisory file lock on path + ".lock". It uses a 1-second timeout with 100ms retry interval.

Types

This section is empty.

Jump to

Keyboard shortcuts

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