writeguard

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 9 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 writeguard stops a test process from writing under the developer's real ocfp directories.

Every function that writes ocfp config, state, data, keys, locks, or logs calls Check with the path it is about to write. In a real run Check returns at once, because only a test process sets EnvVar. In a test process it panics, with the stack of the write, when the path lies under one of the developer's real ocfp directories.

The real directories come from the passwd entry, not from $HOME or the XDG variables, because a test process points those at a temporary tree. A guard that read them would see that tree as the real home and stop every legitimate write.

Index

Constants

View Source
const EnvVar = "OCFP_TEST_SAFETY_GUARD"

EnvVar marks a test process. A test binary's TestMain sets it, and a real run never does.

View Source
const RootsEnvVar = "OCFP_TEST_SAFETY_GUARD_ROOTS"

RootsEnvVar lists more directories to guard, separated by os.PathListSeparator. A test binary's TestMain sets it to the ocfp directories that HOME, the XDG variables, and OCFP_HOME named before it moved them. A developer whose real directories aren't the defaults keeps them guarded that way, and so does a process with no passwd entry.

Variables

This section is empty.

Functions

func Check

func Check(operation, path string)

Check panics when this is a test process and path lies under one of the developer's real ocfp directories. operation names the write in the panic message. An empty path passes, since it names no directory.

When this process has no passwd home and RootsEnvVar is empty, Check panics too. A test process that can't tell where the real directories are can't prove that it stays out of them.

func OverrideRealHome

func OverrideRealHome(dir string) func()

OverrideRealHome makes Check treat dir as the developer's real home until the returned function runs. A test uses it to prove that a write under the real directories panics, without writing under them. It must not run in parallel with another test that calls it.

func Roots

func Roots() ([]string, error)

Roots returns the developer's real ocfp directories. They are the legacy ~/.ocfp and the XDG config, state, data, and cache directories under the passwd home, followed by any that RootsEnvVar lists. A root that a symbolic link leads to appears twice, once by each name. Without a passwd home, Roots returns those that RootsEnvVar lists, and it fails when that list is empty too.

Types

This section is empty.

Jump to

Keyboard shortcuts

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