pathcheck

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package pathcheck reports, once at startup, every filesystem path a binary is configured with: where the value came from (set, or the built-in default), the absolute path it resolves to from the working directory, and whether the file or directory is there and usable by the process user.

Each path is one log line with the message "startup path", so

docker logs <container> 2>&1 | grep 'startup path'

shows the whole picture, and problems are logged at WARN. The report never stops startup. A misconfigured path often fails silently (a missing plugin config file loads no plugins, a missing .env file is skipped), and this is where that shows up.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

func Log(l zerolog.Logger, component string, results []Result) int

Log writes one "startup path" line per result, after a line giving the working directory and process user that relative paths and permissions depend on. Problems are logged at WARN, everything else at INFO. It returns the number of problems.

func SQLitePath

func SQLitePath(dsn string) (path string, onDisk bool)

SQLitePath reduces a SQLite DSN or path to the file it opens. onDisk is false for in-memory databases.

Types

type Entry

type Entry struct {
	// Name is how the path is set, usually its environment variable
	// ("PLUGINS_CONFIG_PATH") or a flag ("-env").
	Name string
	// Value is the value the binary uses, after defaults are applied.
	Value string
	// Default is the value used when Name is not set ("" when there is none).
	Default string
	// Kind decides what is checked.
	Kind Kind
	// Required marks a path the binary cannot work without in its current
	// mode. An unset required path is a problem; an unset optional one just
	// means the feature that uses it is off.
	Required bool
	// Use says what the path is for, in a few words.
	Use string
	// Source overrides the source derived from the environment. Set it for
	// values that do not come from an environment variable (flags).
	Source Source
}

Entry is one configured path.

type Kind

type Kind string

Kind says how a path is used, which decides what is checked.

const (
	// File is read: it must exist and be readable.
	File Kind = "file"
	// Dir is written: it must be a writable directory, or be creatable
	// under a writable parent.
	Dir Kind = "dir"
	// SQLite is a SQLite database, given as a file path or a DSN
	// ("file:./data/x.db?mode=rwc"). It is opened read-write and created on
	// first use, but its directory must already exist, and be writable for
	// the journal/WAL files.
	SQLite Kind = "sqlite"
	// OutputFile is appended to (a log file): writable if it exists, or
	// creatable under a writable parent.
	OutputFile Kind = "output_file"
)

type Result

type Result struct {
	Entry
	Source   Source
	Path     string // the filesystem path checked (a DSN reduced to its file)
	Resolved string // Path made absolute against the working directory
	Status   Status
	Detail   string // why a check failed
}

Result is the outcome of checking one Entry.

func Check

func Check(entries []Entry) []Result

Check examines every entry. It only reads the filesystem, except that a directory's writability is tested by creating and removing a temporary file in it.

func (Result) Problem

func (r Result) Problem() bool

Problem reports whether the result should be flagged. A path that was set, or is required, must work. A default file that is absent is not a problem (a default .env is normally absent in containers), but a default directory or database the binary will write to must be usable.

type Source

type Source string

Source says where a path's value came from.

const (
	SourceSet     Source = "set"     // the environment variable (or flag) was set
	SourceDefault Source = "default" // not set; the built-in default is in use
	SourceUnset   Source = "unset"   // not set and there is no default
)

type Status

type Status string

Status is the outcome of checking one path.

const (
	StatusOK          Status = "ok"
	StatusUnset       Status = "unset"       // not configured
	StatusWillCreate  Status = "will_create" // absent, and the parent is writable
	StatusMissing     Status = "missing"     // absent, and cannot be created
	StatusNotReadable Status = "not_readable"
	StatusNotWritable Status = "not_writable"
	StatusWrongType   Status = "wrong_type" // a directory where a file is expected, or the reverse
	StatusInMemory    Status = "in_memory"  // an in-memory SQLite DSN; nothing on disk
)

Jump to

Keyboard shortcuts

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