filemap

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileMap

type FileMap map[string]string

FileMap is a map of paths to file contents.

func Merge

func Merge(fms ...FileMap) FileMap

Merge merges all fms together.

func (FileMap) Clean

func (f FileMap) Clean(dir string) error

Clean deletes each file defined in f, it leaves any created directories in place. If you want to nuke everything, just use os.RemoveAll(dir).

func (FileMap) Merge

func (f FileMap) Merge(o FileMap) FileMap

Merge attempts to merge 2 filemaps, if any keys conflict it panics.

func (FileMap) Mine

func (f FileMap) Mine(dir, path string) bool

Mine returns true if the file at path relative to dir belongs to this FileMap. Otherwise it returns false.

func (FileMap) Overwrite

func (f FileMap) Overwrite(dir string) error

Overwrite is similar to Write, except any existing files that are also defined in f are overwritten.

func (FileMap) PrefixAll

func (f FileMap) PrefixAll(prefix string) FileMap

PrefixAll prefixes all paths in this FileMap with the provided prefix.

func (FileMap) Session

func (f FileMap) Session(dir string, do func()) error

Session encapsulates tearing-up the file tree defined by f, then running some code that assumes it exists, before cleaning up. If f.Write(dir) fails, do is not run, and the error is returned. Otherwise, do is run, and the error from f.Clean(dir) is returned. If do panics, then f.Clean will not be run, so you can inspect the files created in case they had something to do with it.

func (FileMap) Write

func (f FileMap) Write(dir string) error

Write writes the file tree defined in f to the directory dir. If dir exists and is not empty, or if any errors occur trying to write the file, or create the directory hierarchy, an error is returned, an f.Clean() is called to attempt to clean up any files written.

Jump to

Keyboard shortcuts

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