Help us shape the future of Go! Take the 2026 Go Developer Survey

fsx

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package fsx holds the file operations gotools needs to keep a project safe: writes that are never half done, and a refusal to follow symlinks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lexists

func Lexists(path string) bool

Lexists reports whether path exists, without following a symlink: a dangling symlink exists.

func RejectSymlink(path, context string) error

RejectSymlink returns an Environment error when path is a symlink. A path that does not exist, or cannot be inspected, passes. context names the operation in the message and may be empty.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic writes data to a temp file beside path and renames it over path, so a crash never leaves a half-written file. Existing contents and permissions are replaced, and perm applies to the result. The temp file is created exclusively, so a symlink planted at its name cannot redirect the write.

Types

type Snapshot

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

Snapshot remembers the content of some files so a step that may fail can put them back, or remove them if they did not exist.

func TakeSnapshot

func TakeSnapshot(files ...string) *Snapshot

TakeSnapshot reads files now. A file that cannot be read is treated as absent.

func (*Snapshot) Restore

func (s *Snapshot) Restore()

Restore puts every file back as it was when the snapshot was taken, writing each atomically, and removes the ones that did not exist then.

Jump to

Keyboard shortcuts

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