paths

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package paths resolves where configuration, state and logs live.

The same XDG-style layout is used on macOS and Linux so that the config file is easy to find and edit by hand: ~/.config/<id>/ and ~/.local/state/<id>/. On Linux XDG_CONFIG_HOME and XDG_STATE_HOME move them. On macOS they do not: the menu bar app and launchd never see a shell's XDG variables, so honoring them there would give the CLI another config, state directory, token and lock than the app. Earlier versions did honor them on macOS; MoveLegacy moves what they left there.

Index

Constants

View Source
const (
	// DirMode is the mode of directories created for config and state.
	DirMode os.FileMode = 0o700
	// FileMode is the mode of files written into them.
	FileMode os.FileMode = 0o600
)

The config can hold secrets in server environments and the logs can hold whatever a server prints, so both stay readable by the owner only.

View Source
const (
	TokenName         = "auth-token"     // the API token
	DashboardHostName = "dashboard-host" // the dashboard's host name
	PortName          = "daemon.port"    // the port a running daemon serves
	LockName          = "daemon.lock"    // held by the running daemon
)

Files in the state directory that the daemon writes and its clients read.

Variables

This section is empty.

Functions

func ConfigFile

func ConfigFile() string

ConfigFile returns the path of the main configuration file.

func ConfigLockName

func ConfigLockName(config string) string

ConfigLockName is the file next to the config file named config that serialises edits to it; it stays after an edit.

func DaemonLog

func DaemonLog() string

DaemonLog returns the daemon's own log file.

func Default

func Default(cfgPath, stateDir string) bool

Default reports whether cfgPath and stateDir are the default config file and state directory, as for the account's main daemon rather than an isolated instance.

func DefaultConfigFile

func DefaultConfigFile() string

DefaultConfigFile is the config file used unless the config path is overridden.

func ExpandHome

func ExpandHome(p string) string

ExpandHome replaces a leading ~ and expands $VARS.

func LogDir

func LogDir(stateDir string) string

LogDir returns the directory in stateDir holding one log file per server.

func MoveLegacy

func MoveLegacy() []string

MoveLegacy moves, on macOS, a config file and state directory that an earlier version put under XDG_CONFIG_HOME or XDG_STATE_HOME to the default locations, which macOS uses regardless of those variables (see the package comment). It acts only when the variable is set, points elsewhere than the default, the old location holds the product's files and nothing else (see legacyLocation), the default one does not exist, and the location is not overridden. While a daemon still runs from the old state directory, the login service names an old location, or a move fails, this process uses the old locations instead. It returns one note per change, for the user. Commands run it before they read any location.

func MoveLegacyForService

func MoveLegacyForService(cfgPath string) (string, []string)

MoveLegacyForService is MoveLegacy for `service install`, run once any daemon has stopped: it moves the old locations even when the login service names them, because the service is written anew with the default ones next. It returns the config file to use instead of cfgPath, and the notes.

func Restrict

func Restrict(cfgPath, stateDir string)

Restrict removes group and other access from the product's config and state.

The default config and state directories belong to the product, so they are tightened with everything in them. A config file elsewhere is tightened on its own, and a state directory elsewhere is tightened itself together with the product's files and logs in it; other files in such directories keep their modes. Parent directories such as ~/.config are left alone, and symlinks are not followed.

func SamePath

func SamePath(a, b string) bool

SamePath reports whether a and b name the same location once symlinks in them are resolved.

func ShortenHome

func ShortenHome(p string) string

ShortenHome renders a path with the home directory replaced by ~.

func StateDir

func StateDir() string

StateDir returns the directory for runtime state, logs and the lock file.

func StopMarker

func StopMarker() string

StopMarker returns the file a deliberate daemon stop leaves behind; while it exists, background clients such as the menu bar app do not start a daemon.

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile replaces path with data through a fresh private temporary file in the same directory, so readers never see a partial file and a planted symlink or a concurrent writer cannot take over a fixed temporary name. The directory must exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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