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

durable

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package durable writes the files a later start of funcd trusts, so a power loss leaves the old content or the new one, never an empty or a partial file (#1244): every file and directory is synced before the step that makes it visible, and the directory that holds a renamed or created entry is synced after it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Disk

type Disk struct {
	Trace func(op Op, path string)
}

Disk does durable writes. Its zero value acts on the file system; Trace, when set, gets each step once it is done, so a test can check their order.

func (d Disk) Link(oldpath, newpath string) error

Link makes newpath a second name of oldpath, failing when newpath exists; the caller syncs newpath's directory before it relies on the link.

func (Disk) MkdirAll

func (d Disk) MkdirAll(dir string, perm fs.FileMode) error

MkdirAll makes dir and its missing parents at mode perm, then syncs the parent of each directory it made, outermost first.

func (Disk) Rename

func (d Disk) Rename(oldpath, newpath string) error

Rename moves oldpath to newpath; the caller syncs newpath's directory before it relies on the move.

func (Disk) SyncDir

func (d Disk) SyncDir(dir string) error

SyncDir syncs dir, so the entries created, renamed or removed in it survive a power loss.

func (Disk) SyncFile

func (d Disk) SyncFile(f *os.File) error

SyncFile syncs the open file f's data.

func (Disk) SyncTree

func (d Disk) SyncTree(root string) error

SyncTree syncs every regular file and directory under root, root included, so a rename that publishes root publishes their content too.

func (Disk) WriteFile

func (d Disk) WriteFile(dir, name string, data []byte, perm fs.FileMode) error

WriteFile replaces dir/name with data at mode perm: a temporary file in dir is synced and renamed onto dir/name, then dir is synced.

type Op

type Op string

Op is one step of a durable write, as Disk.Trace reports it.

const (
	SyncFile Op = "sync-file" // a file's data
	SyncDir  Op = "sync-dir"  // a directory's entries
	Rename   Op = "rename"    // an entry moved into place; the path is its new one
	Link     Op = "link"      // an entry made by link(2); the path is its new one
)

Jump to

Keyboard shortcuts

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