Documentation
¶
Overview ¶
Package safeio implements bounded, identity-checked native filesystem operations without exposing file handles to policy code.
On Linux, a mutable root and each destination parent must be owned by the effective user and must not be writable by group or other. Safe cleanup moves owned bytes into a pinned owner-only directory before unlinking them. Writers running as that same trusted user must serialize mutations through safeio; Unix permissions cannot isolate mutually hostile processes with the same UID.
Index ¶
- type Code
- type Entry
- type Error
- type FileTimes
- type Identity
- type Root
- func (root *Root) Close() error
- func (root *Root) Enumerate(maximumEntries int) ([]Entry, error)
- func (root *Root) HashFile(relative string, maximumBytes int64) (string, Identity, error)
- func (root *Root) Inspect(relative string) (Identity, error)
- func (root *Root) ReadFile(relative string, maximumBytes int64) (Snapshot, error)
- func (root *Root) Remove(relative string, expected *Identity) error
- func (root *Root) Stage(destination string, source io.Reader, expectedBytes int64, maximumBytes int64, ...) (*Staged, error)
- func (root *Root) StageDirectory(destination string, mode fs.FileMode) (*StagedDirectory, error)
- type Snapshot
- type Staged
- type StagedDirectory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
Entry is one identity-checked regular file or directory below a Root. Path uses normalized forward slashes. Windows reports native Mode values: regular files have zero type bits and permission bits are not synthesized.
type Error ¶
Error describes a failed operation without exposing platform error details as policy decisions. Retryable is true only for transient sharing failures.
type FileTimes ¶
FileTimes contains deterministic regular-file access and modification times. Values are normalized to UTC microsecond precision on every platform.
type Identity ¶
Identity is a native object identity and observed metadata. Mode is native: Windows reports directory/type information but zero permission bits; callers map separately authenticated logical content modes instead of inferring them.
type Root ¶
type Root struct {
// contains filtered or unexported fields
}
Root confines operations to one native directory handle.
func OpenRoot ¶
OpenRoot opens and pins a directory used as the boundary for later relative operations. Call Close when the root is no longer needed.
func (*Root) Enumerate ¶
Enumerate returns every regular file and directory below the pinned root in lexicographic UTF-8 byte order. maximumEntries counts all directory entries, including entries rejected as links or unsupported types. Enumeration counts before allocating its result and verifies the complete membership and native identities in a second descriptor-relative pass.
func (*Root) HashFile ¶
HashFile streams at most maximumBytes through SHA-256 and verifies identity and size before returning.
func (*Root) Inspect ¶
Inspect observes a regular file without following a final symlink or reparse point.
func (*Root) ReadFile ¶
ReadFile reads at most maximumBytes and rejects identity or size changes that occur during the read.
func (*Root) Remove ¶
Remove durably removes a file, optionally conditioned on its current native identity.
func (*Root) Stage ¶
func (root *Root) Stage( destination string, source io.Reader, expectedBytes int64, maximumBytes int64, mode fs.FileMode, ) (*Staged, error)
Stage copies exactly expectedBytes from source to a durable temporary file. maximumBytes is an independent hard bound and mode must be non-executable. Unix applies all permission bits exactly. Windows applies its exact native mapping: owner-write controls FILE_ATTRIBUTE_READONLY and ACLs stay inherited.
func (*Root) StageDirectory ¶
StageDirectory creates an unpublished private directory beside destination. mode is exact on Unix. Windows directories retain inherited ACLs because FileMode cannot losslessly encode a DACL; owner rwx and no group/other writes remain mandatory policy inputs on every platform.
type Staged ¶
type Staged struct {
// contains filtered or unexported fields
}
Staged is a durable temporary regular file owned by a Root. A caller must choose exactly one terminal operation: CommitReplace or Discard.
func (*Staged) CommitReplace ¶
CommitReplace atomically publishes a staged file. When expected is non-nil, replacement fails unless the destination still has that identity.
type StagedDirectory ¶
type StagedDirectory struct {
// contains filtered or unexported fields
}
StagedDirectory is one private directory tree assembled below a confined Root. The tree remains unpublished until CommitNoReplace and never replaces an existing destination.
func (*StagedDirectory) CommitNoReplace ¶
func (staged *StagedDirectory) CommitNoReplace(destination string) error
CommitNoReplace durably publishes the complete tree if destination is absent.
func (*StagedDirectory) Discard ¶
func (staged *StagedDirectory) Discard() error
Discard durably removes an unpublished staged tree. It is idempotent.
func (*StagedDirectory) Root ¶
func (staged *StagedDirectory) Root() *Root
Root returns the pinned, private root used to populate the staged tree. Callers must stop using it before CommitNoReplace or Discard.