receivefs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 14 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package receivefs validates untrusted receive paths and provides filesystem operations rooted at a directory handle.

Index

Constants

This section is empty.

Variables

View Source
var ErrPathCollision = errors.New("receive path collision")

ErrPathCollision marks destinations that are ambiguous on a supported filesystem or conflict as file and directory paths.

View Source
var ErrSensitivePath = errors.New("sensitive receive path")

ErrSensitivePath marks a path containing a component that receivers must never create from untrusted transfer metadata.

View Source
var ErrUnsafePath = errors.New("unsafe receive path")

ErrUnsafePath marks a path that is not safe to create portably.

Functions

func CollisionKey

func CollisionKey(name string) string

CollisionKey returns the portable comparison form used for duplicate detection on case-insensitive and normalization-insensitive filesystems.

func ForbiddenComponent

func ForbiddenComponent(component string) bool

ForbiddenComponent reports whether a normalized path component names a sensitive receiver-owned directory. Matching uses the same portable Unicode collision key as manifest duplicate detection.

func Normalize

func Normalize(name string, allowRoot bool) (string, error)

Normalize converts a portable relative path to NFC slash form. Root may be represented by an empty string or dot only when allowRoot is true. Keep the browser twin in web/src/protocol/metadata.ts aligned with these rules.

Types

type Entry

type Entry struct {
	Path string
	Kind Kind
}

Entry is an untrusted destination path and its intended type.

func ValidateEntries

func ValidateEntries(entries []Entry) ([]Entry, error)

ValidateEntries normalizes a complete untrusted manifest and rejects exact, case-folded, normalization-equivalent, and file/directory collisions.

type Kind

type Kind uint8

Kind identifies the type of object an untrusted manifest will create.

const (
	KindFile Kind = iota
	KindDirectory
	KindSymlink
)

type Root

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

Root performs receive operations relative to one opened destination root. os.Root keeps operations contained even when path components are replaced concurrently.

func OpenRoot

func OpenRoot(name string) (*Root, error)

OpenRoot opens an existing destination directory.

func (*Root) Chtimes

func (r *Root) Chtimes(name string, atime, mtime time.Time) error

func (*Root) Close

func (r *Root) Close() error

func (*Root) CreateTemp

func (r *Root) CreateTemp(dir, prefix string, perm fs.FileMode) (*os.File, string, error)

CreateTemp creates an exclusive random file below dir and returns its root-relative slash path.

func (*Root) CreateTempDir

func (r *Root) CreateTempDir(dir, prefix string) (string, error)

CreateTempDir creates an exclusive private directory below dir and returns its root-relative slash path.

func (*Root) Lstat

func (r *Root) Lstat(name string) (fs.FileInfo, error)

func (*Root) MkdirAll

func (r *Root) MkdirAll(name string, perm fs.FileMode) error

func (*Root) Name

func (r *Root) Name() string

func (*Root) Open

func (r *Root) Open(name string) (*os.File, error)

func (*Root) OpenFile

func (r *Root) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)

OpenFile opens a validated path while preserving os.OpenFile flag behavior.

func (*Root) RejectSymlinkPath

func (r *Root) RejectSymlinkPath(name string) error

RejectSymlinkPath preserves croc's refusal of existing symlink components. The subsequent os.Root operation supplies containment if a component changes after this inspection.

func (*Root) Remove

func (r *Root) Remove(name string) error

func (*Root) RemoveAll

func (r *Root) RemoveAll(name string) error

func (*Root) Rename

func (r *Root) Rename(oldName, newName string) error

func (*Root) Stat

func (r *Root) Stat(name string) (fs.FileInfo, error)
func (r *Root) Symlink(target, name string) error

func (*Root) WriteFileAtomic

func (r *Root) WriteFileAtomic(name string, data []byte, perm fs.FileMode) error

WriteFileAtomic writes, syncs, and renames a private file over name.

Jump to

Keyboard shortcuts

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