utils

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: GPL-3.0 Imports: 6 Imported by: 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DuplicateBytes

func DuplicateBytes(a []byte) []byte

DuplicateBytes returns a new copy of the given byte slice.

func DuplicateStrings

func DuplicateStrings(a []string) []string

DuplicateStrings returns a new copy of the given string slice.

func EnsureDirectory added in v0.3.0

func EnsureDirectory(path string, perm os.FileMode) error

EnsureDirectory ensures that the given directory exists and that is has the given permissions set. If path is a file, it is deleted and a directory created. If a directory is created, also all missing directories up to the required one are created with the given permissions.

func IndexOfString

func IndexOfString(a []string, s string) int

IndexOfString returns the index of given string and -1 if its not part of the slice.

func RemoveFromStringSlice

func RemoveFromStringSlice(a []string, s string) []string

RemoveFromStringSlice removes the given string from the slice and returns a new slice.

func StringInSlice

func StringInSlice(a []string, s string) bool

StringInSlice returns whether the given string is in the string slice.

func StringSliceEqual

func StringSliceEqual(a []string, b []string) bool

StringSliceEqual returns whether the given string slices are equal.

Types

type DirStructure added in v0.3.0

type DirStructure struct {
	sync.Mutex

	Path     string
	Dir      string
	Perm     os.FileMode
	Parent   *DirStructure
	Children map[string]*DirStructure
}

DirStructure represents a directory structure with permissions that should be enforced.

Example

Output:

/ [755]
/repo [777]
/repo/b [755]
/repo/b/c [750]
/repo/b/d [755]
/repo/b/d/e [755]
/repo/b/d/f [755]
/secret [700]

func NewDirStructure added in v0.3.0

func NewDirStructure(path string, perm os.FileMode) *DirStructure

NewDirStructure returns a new DirStructure.

func (*DirStructure) ChildDir added in v0.3.0

func (ds *DirStructure) ChildDir(dirName string, perm os.FileMode) (child *DirStructure)

ChildDir adds a new child DirStructure and returns it. Should the child already exist, the existing child is returned and the permissions are updated.

func (*DirStructure) Ensure added in v0.3.0

func (ds *DirStructure) Ensure() error

Ensure ensures that the specified directory structure (from the first parent on) exists.

func (*DirStructure) EnsureAbsPath added in v0.3.0

func (ds *DirStructure) EnsureAbsPath(dirPath string) error

EnsureAbsPath ensures that the specified directory structure (from the first parent on) and the given absolute path exists. If the given path is outside the DirStructure, an error will be returned.

func (*DirStructure) EnsureRelDir added in v0.3.0

func (ds *DirStructure) EnsureRelDir(dirNames ...string) error

EnsureRelDir ensures that the specified directory structure (from the first parent on) and the given relative path (to the DirStructure) exists.

func (*DirStructure) EnsureRelPath added in v0.3.0

func (ds *DirStructure) EnsureRelPath(dirPath string) error

EnsureRelPath ensures that the specified directory structure (from the first parent on) and the given relative path (to the DirStructure) exists.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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