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

regfile

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package regfile opens files that are REGULAR files, and nothing else.

⚠⚠ Why this exists (issue #38). A directory on disk can hold things that are not files at all: a named pipe (FIFO), a Unix socket, a block or character device. Docker's overlay directories are full of them. Opening a named pipe for reading BLOCKS until something opens its other end — which, for a pipe nobody writes to, is forever. The local storage driver treated every entry that was not a folder or a symlink as a file and opened it to sniff its type, so one `mkfifo` anywhere under a local storage root hung the storage scan in `running` with nothing processed, and every scan after it queued behind the hung one. A socket or a device is no better: a socket cannot be opened at all, and opening a device can have side effects (a tape rewinds).

filex serves regular files and folders. Everything else is skipped by the walks (Special says which) and refused by every open that goes through here — and the open refuses WITHOUT blocking: an entry that turns into a pipe between the check and the open is opened non-blocking, looked at, and closed.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotRegular = errors.New("not a regular file")

ErrNotRegular is what an open of anything but a regular file answers. It is wrapped in an *fs.PathError, so errors.Is(err, ErrNotRegular) finds it.

Functions

func KindOf

func KindOf(m fs.FileMode) string

KindOf names what a special entry is, for a log line an operator reads.

func Open

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

Open opens name for reading if it is a regular file.

func OpenFile

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

OpenFile is os.OpenFile for regular files only. A path that already exists as anything else — a folder included — is refused before it is opened: an open of a device node is itself an action. What is left is the race where a pipe appears between that look and the open; the open is therefore made non-blocking where the platform has pipes (see nonBlock), and the opened descriptor is checked again before it is handed out.

⚠ The flag stays on the returned file. On a regular file O_NONBLOCK changes nothing — disk reads and writes block the way they always do — so there is no second syscall to clear it.

func Special

func Special(m fs.FileMode) bool

Special reports whether m is a named pipe, socket, device node or irregular file. Folders, regular files and symlinks are NOT special — a symlink is judged by its target, which the caller has to Stat.

Types

type Skipped

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

Skipped says, once per path, that a walk turned a special entry away.

⚠ Once per path per process, not once per walk: a storage is rescanned every few minutes, and the same named pipe reported on every pass buries everything else in the log. The zero value is ready to use; keep one per driver so a second storage with its own pipes still gets its own lines.

func (*Skipped) Report

func (s *Skipped) Report(driver, root, path string, mode fs.FileMode)

Report logs that `path` under the storage rooted at `root` was skipped.

Jump to

Keyboard shortcuts

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