util

package
v0.0.0-...-5eebc06 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package util contains common functions for use in the osconfig agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWrite

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

AtomicWrite attempts to atomically write a file.

func AtomicWriteFileStream

func AtomicWriteFileStream(r io.Reader, checksum, path string, mode os.FileMode) (string, error)

AtomicWriteFileStream attempts to atomically write data from the provided reader to the path checking the checksum if provided.

func Exists

func Exists(name string) bool

Exists check for the existence of a file

func NormPath

func NormPath(path string) (string, error)

NormPath transforms a windows path into an extended-length path as described in https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath when not running on windows it will just return the input path.

func TempFile

func TempFile(dir string, pattern string, mode os.FileMode) (f *os.File, err error)

TempFile is a little bit like ioutil.TempFile but takes FileMode in order to work nicely on Windows where File.Chmod is not supported.

Types

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, command *exec.Cmd) ([]byte, []byte, error)
}

CommandRunner will execute the commands and return the results of that execution.

type DefaultRunner

type DefaultRunner struct{}

DefaultRunner is a default CommandRunner.

func (*DefaultRunner) Run

func (r *DefaultRunner) Run(ctx context.Context, cmd *exec.Cmd) ([]byte, []byte, error)

Run takes precreated exec.Cmd and returns the stdout and stderr.

type Logger

type Logger struct {
	Debugf   func(string, ...any)
	Infof    func(string, ...any)
	Warningf func(string, ...any)
	Errorf   func(string, ...any)
	Fatalf   func(string, ...any)
}

Logger holds log functions.

Directories

Path Synopsis
Package utilmocks is a generated GoMock package.
Package utilmocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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