config

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: AGPL-3.0 Imports: 13 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 config locates RemoHop's on-disk state.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("locked by another remohop process")

ErrLocked means another process holds a lock (Lock).

View Source
var ErrNoAccess = errors.New("no access to RemoHop's settings folder")

ErrNoAccess means this account, with the rights it has now, may not use a directory RemoHop keeps its settings in (an *AccessError says which).

Functions

func AccessReport added in v1.0.13

func AccessReport(path string) string

AccessReport describes who may use path, for a log line when this process cannot write where it should: its mode and owner, and this process's user.

func All

func All() (map[string]string, error)

All returns every value stored in the config file.

func AllIn

func AllIn(dir string) (map[string]string, error)

AllIn returns every value stored in the config file of a specific config directory. Long-running processes that were started on a directory read their live settings through it.

func Bool

func Bool(value string, def bool) bool

Bool interprets a stored on/off value; anything else, including an unset key, yields def.

func CanWrite added in v1.0.13

func CanWrite(dir string) error

CanWrite reports whether this process can create files and directories in dir, by creating (and removing) a directory with a file in it. It answers for this process's own token, which an access list read by eye may not (an administrator without elevation, say). The error says why not.

func CheckAccess added in v1.0.13

func CheckAccess(dir string) error

CheckAccess reports, as an *AccessError, a directory this process may not create files in for lack of rights (CanWrite); any other failure is returned as it is.

func Dir

func Dir() (string, error)

Dir is where configuration and credentials live: $REMOHOP_CONFIG_DIR, or "remohop" under the user's config directory (~/.config/remohop on Linux). The directory is created with mode 0700 because it holds key material.

func Get

func Get(key string) (string, error)

Get returns the stored value for key, or "" when it is not set.

func IsPrivate

func IsPrivate(path string) (bool, error)

IsPrivate reports whether path is inaccessible to group and others.

func Lock

func Lock(path string) (unlock func(), err error)

Lock takes a cross-process advisory lock guarding path, for the read-modify-write cycles on small state files that several remohop processes share (saved peers, pairing tokens). The lock is an operating-system file lock (flock, LockFileEx) on path+".lock": it is released by the system if the holder dies, so there is nothing stale to clean up, and the lock file itself is never deleted, because removing a file that another process has open or is about to open is exactly what does not work on Windows. Call the returned function to release.

func MakePrivate

func MakePrivate(dir string) error

MakePrivate makes sure dir is a safe place for this user's key material. Files in it are created 0600 by every writer in this module, but that does not stop someone who can write to the directory from replacing them (a rename needs only write access to the directory), so:

  • a directory of this user's that others may write to is tightened to the owner only (not a sticky directory such as /tmp, which is shared by design);
  • a directory that belongs to another user (other than root) is refused;
  • one that everybody may write to and that cannot be fixed is refused.

Group write is accepted when it cannot be removed (the directory is root's: a volume shared with a container's group, say). A directory that others can only read is left as it is.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile is os.ReadFile made tolerant of the transient sharing violations described at replaceFile: on Windows a read that races a WriteFileAtomic rename over the same file can fail for a moment. A file that does not exist is reported at once.

func RegisterSetting

func RegisterSetting(s Setting)

RegisterSetting declares a config key. It panics on a duplicate so two packages cannot silently share one.

func Remove added in v1.0.12

func Remove(path string) error

Remove is os.Remove made tolerant of the transient sharing violations described at replaceFile: on Windows a file that another remohop process is reading at this instant cannot be deleted for a moment. A file that does not exist is reported at once.

func Rename

func Rename(oldpath, newpath string) error

Rename is os.Rename made tolerant of the transient sharing violations described at replaceFile; use it to rotate or replace files that other remohop processes may be reading.

func Set

func Set(key, value string) error

Set stores value under key; an empty value removes the key. The key must have been declared and the value must pass its validation.

func SubDir

func SubDir(name string) (string, error)

SubDir returns (and creates, mode 0700) a named directory under Dir, for feature state such as clipboard history or spawn logs.

func ValidateOnOff

func ValidateOnOff(v string) error

ValidateOnOff is a Setting.Validate for on/off keys.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic replaces path with data so that a reader (or a crash) sees either the old or the new content, never a mix: the bytes go to a temporary file in the same directory, are synced, and are renamed over the target.

Types

type AccessError added in v1.0.13

type AccessError struct {
	Dir string
	Err error // the system's error
}

AccessError is ErrNoAccess for one directory, with what to do about it.

func (*AccessError) Error added in v1.0.13

func (e *AccessError) Error() string

func (*AccessError) Unwrap added in v1.0.13

func (e *AccessError) Unwrap() []error

type RepairResult added in v1.0.13

type RepairResult struct {
	// Ran: this process is elevated and the directory is the user's own,
	// so it went through it.
	Ran bool
	// Fixed and Failed count the files and directories whose owner or
	// list it changed, and those it could not.
	Fixed, Failed int
	// Err is the first failure.
	Err error
}

RepairResult is what RepairAccess did.

func RepairAccess added in v1.0.13

func RepairAccess(dir string) RepairResult

RepairAccess does nothing on Unix: a run as root does not hand files back to a user.

type Setting

type Setting struct {
	Key  string
	Help string
	// Validate rejects malformed values; nil accepts anything.
	Validate func(value string) error
	// Secret values are masked when all settings are listed.
	Secret bool
	// Default is shown in listings for a key that is not set.
	Default string
}

Setting describes one key of the user's config file (config.json in Dir), edited with `remohop config set`. Packages declare the keys they read with RegisterSetting so the command can validate and document them.

func LookupSetting

func LookupSetting(key string) (Setting, bool)

LookupSetting finds a declared key.

func Settings

func Settings() []Setting

Settings lists the declared keys, sorted.

Jump to

Keyboard shortcuts

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