platform

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetachProcess

func DetachProcess(cmd *exec.Cmd)

DetachProcess configures cmd to run in a new session, detached from the parent. The child survives the parent exiting.

func HideWindow added in v0.3.2

func HideWindow(_ *exec.Cmd)

HideWindow is a no-op on Unix. On Windows it suppresses console window creation for subprocess invocations from detached workers.

func LockFile

func LockFile(f *os.File) error

LockFile acquires an exclusive lock on the entire file.

func LooksAbsolutePath

func LooksAbsolutePath(path string) bool

LooksAbsolutePath returns true if path looks like an absolute path on any OS. Unlike filepath.IsAbs, this recognizes POSIX-style absolute paths (/workspace/...) even on Windows, which is needed for file paths from agent payloads that may use POSIX conventions regardless of host OS.

func NormalizePathForCompare added in v0.3.2

func NormalizePathForCompare(p string) string

NormalizePathForCompare returns a path suitable for case-aware prefix matching. On Windows, paths are lowercased because the filesystem is case-insensitive (C:\Users and c:\Users are the same path). On macOS/Linux, the path is returned unchanged.

func ReplaceFile added in v0.6.0

func ReplaceFile(src, dst string) error

ReplaceFile replaces dst without removing it first, avoiding a missing-destination window. On Windows it uses MoveFileEx with replace-existing and write-through flags and retries transient file access errors. Use it when dst must remain present during replacement.

func SafeRename

func SafeRename(src, dst string) error

SafeRename moves src to dst, replacing dst if it exists. On Windows, it removes dst first because os.Rename cannot overwrite an existing file. It retries transient sharing, lock, and access errors caused by concurrent readers or writers. This is not atomic on Windows.

func SetProcessGroup

func SetProcessGroup(cmd *exec.Cmd)

SetProcessGroup configures cmd to run in a new process group.

func TermSignals

func TermSignals() []os.Signal

TermSignals returns the signals to listen for graceful shutdown.

func TryLockFile added in v0.6.0

func TryLockFile(f *os.File) (bool, error)

TryLockFile attempts to acquire an exclusive lock without blocking. Returns false when another holder has the lock.

func UnlockFile

func UnlockFile(f *os.File) error

UnlockFile releases the lock on the file.

func UpdateFileLocked added in v0.6.1

func UpdateFileLocked(ctx context.Context, path string, defaultMode os.FileMode, merge func(current []byte) ([]byte, error)) error

UpdateFileLocked serializes an atomic read-modify-write. merge receives nil for a missing file; returning nil leaves the destination unchanged.

func WithFileLock added in v0.6.1

func WithFileLock(ctx context.Context, path string, fn func() error) error

WithFileLock runs fn under a process-shared lock associated with path. Waiting for the lock honors ctx.

func WithoutLoopbackProxies added in v0.3.5

func WithoutLoopbackProxies(env []string) []string

WithoutLoopbackProxies returns a copy of env with any proxy variable whose value points at a literal loopback host removed. Other entries are preserved in their original order.

This drops short-lived localhost proxies inherited from the parent process while keeping real forward proxies in place.

Loopback recognition is syntactic only - no DNS resolution is performed, keeping the function deterministic and side-effect free on the spawn path. A host is treated as loopback when it is exactly "localhost" or when it parses as an IP inside 127.0.0.0/8 or equal to "::1". Scheme-less values like "127.0.0.1:64788" are parsed as if they had an "http://" prefix for inspection only.

func WriteFileAtomic added in v0.6.1

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

WriteFileAtomic replaces path through a synced sibling file. Existing permissions are preserved; defaultMode applies when path does not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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