util

package
v0.0.0-...-907bc6e Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PrivateFileMode grants owner to read/write a file.
	PrivateFileMode = 0o600
)

Variables

This section is empty.

Functions

func AtomicCopy

func AtomicCopy(srcFilepath, targetDir, targetFilename string) error

Copies file by reading the file then writing atomically into the target directory

func AtomicWrite

func AtomicWrite(path string, data []byte, mode os.FileMode) (err error)

Write atomically by writing to a temporary file in the same directory then renaming

func Copy

func Copy(srcFilepath, targetDir, targetFilename string) error

func CreateFileWatcher

func CreateFileWatcher(dir string) (watcher *fsnotify.Watcher, fileModified chan bool, errChan chan error, err error)

Creates a file watcher that watches for any changes to the directory

func DirEquals

func DirEquals(a, b string) (bool, error)

DirEquals check if two directories are referring to the same directory

func Exists

func Exists(name string) bool

func GetPlugin

func GetPlugin(rawPlugin interface{}) (plugin map[string]interface{}, err error)

Given the raw plugin interface, return the plugin asserted as a map[string]interface{}

func GetPlugins

func GetPlugins(cniConfigMap map[string]interface{}) (plugins []interface{}, err error)

Given an unmarshalled CNI config JSON map, return the plugin list asserted as a []interface{}

func IsDirWriteable

func IsDirWriteable(dir string) error

IsDirWriteable checks if dir is writable by writing and removing a file to dir. It returns nil if dir is writable. Inspired by etcd fileutil.

func MarshalCNIConfig

func MarshalCNIConfig(cniConfigMap map[string]interface{}) ([]byte, error)

Marshal the CNI config map and append a new line

func ReadCNIConfigMap

func ReadCNIConfigMap(path string) (map[string]interface{}, error)

Read CNI config from file and return the unmarshalled JSON as a map

func WaitForFileMod

func WaitForFileMod(ctx context.Context, fileModified chan bool, errChan chan error) error

Waits until a file is modified (returns nil), the context is cancelled (returns context error), or returns error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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