fsutil

package
v0.0.0-...-edff0cb Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCopyMaxFiles int64 = 1_000_000
	DefaultCopyMaxBytes int64 = 20 << 30
)

Variables

This section is empty.

Functions

func AllocatedFileBytes

func AllocatedFileBytes(_ string, info fs.FileInfo) (int64, bool)

AllocatedFileBytes returns filesystem blocks allocated to a regular file.

func AllocationMeasurementSupported

func AllocationMeasurementSupported() bool

func CopyDir

func CopyDir(src, dst string) error

func CopyFile

func CopyFile(src, dst string) error

func MovePathWritable

func MovePathWritable(source, destination string) error

MovePathWritable renames one path without following it, temporarily making restrictive source and destination parents owner-writable. Source and destination must be on the same filesystem. Validation uses this to transfer ownership of disposable projected artifacts without allocating a second expanded tree.

func Realpath

func Realpath(path string) (string, error)

func RemoveAllWritable

func RemoveAllWritable(path string) error

RemoveAllWritable repairs restrictive copied/cache permissions before cleanup. WalkDir does not follow symlinks, so chmod never escapes path.

func RemoveIfExists

func RemoveIfExists(path string) error

func ReplaceFile

func ReplaceFile(oldPath, newPath string) error

ReplaceFile atomically replaces newPath with oldPath. Replacements targeting the same path are serialized within the process; the platform implementation handles transient operating-system replacement conflicts.

func WriteEnvFile

func WriteEnvFile(path string, env map[string]string) error

Types

type Copier

type Copier struct {
	// contains filtered or unexported fields
}

func NewCopier

func NewCopier(options CopyOptions) *Copier

func (*Copier) Copy

func (c *Copier) Copy(ctx context.Context, projectionRoot, source, destination string) error

Copy projects source into destination. projectionRoot is the source-side security boundary used for relative paths and symlink validation. A Copier can be reused for several Copy calls so its byte/file limits cover the whole logical projection.

func (*Copier) Progress

func (c *Copier) Progress() CopyProgress

type CopyEntry

type CopyEntry struct {
	Path string
	Info fs.FileInfo
}

type CopyOptions

type CopyOptions struct {
	// MaxFiles and MaxBytes default to conservative finite limits when zero.
	// Set either value below zero only for a caller that deliberately wants no
	// limit.
	MaxFiles   int64
	MaxBytes   int64
	Include    func(CopyEntry) bool
	OnProgress func(CopyProgress)
	Reserve    func(CopyReservation) error
	OnStored   func(CopyStored)
}

type CopyProgress

type CopyProgress struct {
	Path  string `json:"path,omitempty"`
	Files int64  `json:"files"`
	Bytes int64  `json:"bytes"`
	Done  bool   `json:"done,omitempty"`
}

type CopyReservation

type CopyReservation struct {
	Path  string
	Files int64
	Bytes int64
}

type CopyStored

type CopyStored struct {
	Path             string
	AllocatedBytes   int64
	PhysicalMeasured bool
}

Jump to

Keyboard shortcuts

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