Documentation
¶
Overview ¶
Package config locates RemoHop's on-disk state.
Index ¶
- Variables
- func AccessReport(path string) string
- func All() (map[string]string, error)
- func AllIn(dir string) (map[string]string, error)
- func Bool(value string, def bool) bool
- func CanWrite(dir string) error
- func CheckAccess(dir string) error
- func Dir() (string, error)
- func Get(key string) (string, error)
- func IsPrivate(path string) (bool, error)
- func Lock(path string) (unlock func(), err error)
- func MakePrivate(dir string) error
- func ReadFile(path string) ([]byte, error)
- func RegisterSetting(s Setting)
- func Remove(path string) error
- func Rename(oldpath, newpath string) error
- func Set(key, value string) error
- func SubDir(name string) (string, error)
- func ValidateOnOff(v string) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type AccessError
- type RepairResult
- type Setting
Constants ¶
This section is empty.
Variables ¶
var ErrLocked = errors.New("locked by another remohop process")
ErrLocked means another process holds a lock (Lock).
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
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 AllIn ¶
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 ¶
Bool interprets a stored on/off value; anything else, including an unset key, yields def.
func CanWrite ¶ added in v1.0.13
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
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 ¶
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 Lock ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
SubDir returns (and creates, mode 0700) a named directory under Dir, for feature state such as clipboard history or spawn logs.
func ValidateOnOff ¶
ValidateOnOff is a Setting.Validate for on/off keys.
func WriteFileAtomic ¶
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
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 ¶
LookupSetting finds a declared key.