tmpfriend

package module
v0.0.0-...-86e8890 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2018 License: MIT Imports: 8 Imported by: 9

README

tmpfriend Travis-CI GoDoc

tmpfriend is a Go library to help prevent misbehaving subprocesses / code from forgetting to cleanup after themselves. It works by modifying the location of the temporary directory to one unique for the current process, and on start will clean up older temporary directories for non-existant processes.

func main() {
	cleanup := tmpfriend.SetupOrNOOP()
	defer cleanup()
	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTmpFriendDir

func IsTmpFriendDir(rootDir string) bool

IsTmpFriendDir returns true if we are in a tmpfriend dir.

func RootTempDir

func RootTempDir(rootDir string) (func(), error)

RootTempDir creates a new TMPDIR tied to this process, as well as cleaning up TMPDIRs from defunct processes.

TMPDIR is used by both ioutil.TempDir and os.TempDir. The callback returned will cleanup TMPDIR and restore its old value. Note this function is not safe to use concurently since modifying the environment is shared by the whole process.

To use put code like this somewhere like `func main()`

if !IsTmpFriendDir("") {
  f, err := tmpfriend.RootTempDir("")
  if err != nil {
    return err
  }
  defer f()
}
...

func SetupOrNOOP

func SetupOrNOOP() func()

SetupOrNOOP is the expected way to use tmpfriend. It is a wrapper around RootTempDir and IsTmpFriendDir. It will always return a cleanup function, and will do a NOOP under error.

cleanup := tmpfriend.SetupOrNOOP()
defer cleanup()
...

Types

This section is empty.

Jump to

Keyboard shortcuts

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