safety

package
v1.22.8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package safety provides safe deletion operations that protect user configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAllowed

func IsAllowed(policy Policy, target string) bool

IsAllowed checks if a path is in the allowed deletion list.

func IsProtected

func IsProtected(policy Policy, target string) bool

IsProtected checks if a path is protected by the given policy.

func MustRemoveAll

func MustRemoveAll(policy Policy, target string)

MustRemoveAll is like RemoveAll but panics on policy violation. Use only in tests or when you're absolutely sure the path is safe.

func RemoveAll

func RemoveAll(policy Policy, target string) error

RemoveAll safely removes a directory or file, respecting the policy. It returns an error if the target is protected or not in an allowed path.

func RemoveAllUnsafe

func RemoveAllUnsafe(target string) error

RemoveAllUnsafe removes a path without policy checks. This should ONLY be used in very specific cases with explicit user confirmation. The caller is responsible for ensuring safety.

func RemoveChainConfig

func RemoveChainConfig(baseDir, chainName string) error

RemoveChainConfig removes a specific chain configuration directory. This is a special-case function for user-confirmed chain deletion. It requires that the target is a direct subdirectory of the chains directory, NOT the chains directory itself. The caller must ensure user confirmation. baseDir is the Lux base directory (e.g., ~/.lux)

Types

type Policy

type Policy struct {
	BaseDir       string   // The Lux base directory (e.g., ~/.lux)
	AllowPrefixes []string // absolute paths allowed to delete under
	DenyPrefixes  []string // absolute paths never deletable
}

Policy defines which paths are allowed or denied for deletion.

func DefaultPolicy

func DefaultPolicy(baseDir string) Policy

DefaultPolicy returns the standard safety policy for the CLI. It allows deletion of ephemeral runtime state but protects user configuration. baseDir is the Lux base directory (e.g., ~/.lux)

Jump to

Keyboard shortcuts

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