os

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup() error

Cleanup removes the entire process-specific temp directory. Note: After Cleanup(), TempDir() will still return the deleted path. Callers should not use TempDir() after Cleanup(). Note: On Windows, directory deletion may fail if files are still open.

func CreateTemp

func CreateTemp(dir, pattern string) (*os.File, error)

CreateTemp creates a temporary file, using the process-specific directory when dir is empty

func MkdirTemp

func MkdirTemp(dir, pattern string) (string, error)

MkdirTemp creates a temporary directory, using the process-specific directory as base when dir is empty

func TempDir

func TempDir() string

TempDir returns the process-specific temp directory path

Types

type Root added in v0.72.0

type Root struct {
	*os.Root
}

Root is a traversal-resistant handle to a directory. It embeds *os.Root (https://pkg.go.dev/os#Root), so every name passed to its methods is confined to the directory. Root adds NewRoot and Join.

func NewRoot added in v0.72.0

func NewRoot(dir string) (*Root, error)

NewRoot creates dir (0700) if necessary and opens it as a Root. Like os.OpenRoot, it returns an error if the directory cannot be opened.

func (*Root) Join added in v0.72.0

func (r *Root) Join(name string) (string, error)

Join validates name and returns it joined to the root directory. It rejects names that escape the root either literally (filepath.IsLocal handles "..", absolute paths, and escapes hidden behind a missing component) or through an existing symlink (the embedded os.Root). A name that does not exist yet is allowed, so the caller can resolve a destination before creating it.

The result is a plain string, so it is not protected against a later symlink swap (TOCTOU): use it to hand a confined path to an external tool, and use the os.Root methods directly for ordinary I/O.

Jump to

Keyboard shortcuts

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