fileio

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: BSD-2-Clause Imports: 11 Imported by: 0 modules, 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 fileio owns temporary command files and atomic JSON replacement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckJSONPaths

func CheckJSONPaths(paths ...string) error

CheckJSONPaths refuses paths that encoding/json would silently change to different names.

func Create

func Create(dir string) (*os.File, error)

Create exclusively allocates a command scratch file beside its eventual destination.

func Link(src, dir string) (string, error)

Link exclusively allocates a temporary hardlink; it never removes a colliding entry.

func ReadJSON

func ReadJSON(path string, value any) error

ReadJSON loads exactly one nonnull document, refusing bytes JSON would silently replace.

func Remove

func Remove(path string) error

Remove removes only a path the caller already owns through successful allocation or saved state.

func WriteJSON

func WriteJSON(path string, value any, indent bool) (err error)

WriteJSON replaces one document only after encoding, syncing and closing its exclusive file.

Types

type CleanupError

type CleanupError struct {
	Path string
	Err  error
}

CleanupError identifies an owned path that could not be removed and must remain recorded.

func (*CleanupError) Error

func (e *CleanupError) Error() string

func (*CleanupError) Unwrap

func (e *CleanupError) Unwrap() error

type Output

type Output struct {
	File      *os.File
	Path      string
	Temporary string
}

Output owns a destination descriptor and, when staged, its exclusive temporary path. Owners hand it off sequentially; callers must wait for all users before discarding it. A direct device has a File and Path but no Temporary, so cleanup never removes it.

func NewOutput

func NewOutput(path string) (*Output, error)

NewOutput creates an open temporary in the destination's directory.

func (*Output) Close

func (o *Output) Close() error

Close releases the descriptor once, including when closing it fails.

func (*Output) Commit

func (o *Output) Commit(overwrite bool) error

Commit closes the descriptor and replaces Path, retaining ownership on rename failure.

func (*Output) Discard

func (o *Output) Discard() error

Discard closes the descriptor and removes its temporary, retaining any failed removal.

type RewriteItem

type RewriteItem struct {
	Path   string
	Info   os.FileInfo
	Output *Output
}

RewriteItem passes an already-open output and observed source metadata to the copy engine. The command persists Temporary before submission and discards Output only after Wait.

func (*RewriteItem) Source

func (i *RewriteItem) Source() string

Source returns the original file's path.

func (*RewriteItem) Targets

func (i *RewriteItem) Targets() []string

Targets reports the final path; Output owns the separate temporary used during copying.

Jump to

Keyboard shortcuts

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