paths

package
v0.35.0 Latest Latest
Warning

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

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

Documentation

Overview

Package paths resolves where ovdb keeps its configuration, runtime state and data, and creates those directories owner-only — but only the ones it creates itself. Every caller receives a Dirs value instead of reading the environment, so tests inject temporary directories and run in parallel.

See spec/features/local-server-and-web-console#REQ:owner-only-state and the Locations table there. The legacy `ovdb cloud` commands keep resolving os.UserConfigDir() on their own.

Index

Constants

View Source
const (
	EnvHome       = "OVDB_HOME"
	EnvRuntimeDir = "OVDB_RUNTIME_DIR" // hidden: tests and diagnostics only
	EnvDataHome   = "OVDB_DATA_HOME"
)

Environment variables that override the default locations.

Variables

View Source
var ErrNotPrivate = errors.New("directory is accessible to other users")

ErrNotPrivate reports an existing directory other accounts can access.

Functions

func EnsurePrivateDir

func EnsurePrivateDir(dir string) error

EnsurePrivateDir makes dir exist. Every directory it creates on the way (dir and any missing parents) is made owner-only and validated; a directory that already existed is never changed. If dir already existed and is not owner-only it returns an error wrapping ErrNotPrivate — the caller decides whether that is a warning (OVDB home) or a refusal (runtime directory).

func ExpandHome added in v0.14.0

func ExpandHome(path, home string) string

ExpandHome is path with a leading ~ (alone, or before a separator) replaced by home, as a shell expands it: the TUI and web console have no shell to do it for them. ~user forms are left as they are.

func PrivacyFix

func PrivacyFix(dir string) string

PrivacyFix is the command that makes dir owner-only, runnable as printed in this platform's shell: PowerShell on Windows, a POSIX shell elsewhere.

func QuoteArg

func QuoteArg(goos, s string) string

QuoteArg quotes s as one shell argument when it needs quoting: single quotes in both PowerShell (” escapes a quote) and POSIX shells ('\” does).

func WriteFilePrivate

func WriteFilePrivate(path string, data []byte) (err error)

WriteFilePrivate atomically replaces path with data as an owner-only file: it writes a temporary file in the same directory, protects and validates it, syncs it and renames it over path.

Types

type Dirs

type Dirs struct {
	Home    string `json:"home"`    // configuration: config.yaml, databases/, auth.json
	Runtime string `json:"runtime"` // server.json, home.lock, secret, server.log
	Data    string `json:"data"`    // new databases and demos
}

Dirs are the three locations one ovdb installation uses.

func Resolve

func Resolve(env Getenv) (Dirs, error)

Resolve returns the locations for env, making each absolute. Defaults are os.UserConfigDir()/ovdb, os.UserCacheDir()/ovdb/run (LocalAppData on Windows, never the roaming profile) and ~/ovdb.

func (Dirs) Env

func (d Dirs) Env() []string

Env returns the variables that make a child process resolve exactly d.

type Getenv

type Getenv func(string) string

Getenv looks up an environment variable; os.Getenv satisfies it.

Jump to

Keyboard shortcuts

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