utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DownloadBufferSize = 4096

DownloadBufferSize is the number of bytes to transfer from the stream to the downloaded file per iteration. It is 4kb

Variables

View Source
var CacheDir string

CacheDir is used for cpackget to temporarily host downloaded pack files before moving it to CMSIS_PACK_ROOT

View Source
var HTTPClient *http.Client
View Source
var MaxDownloadSize = int64(20 * 1024 * 1024 * 1024)

MaxDownloadSize determines that the max file to be downloaded. Defaults to 20G It prevents malicious requests from providing infinite or very long files

View Source
var ShouldAbortFunction func() bool

ShouldAbortFunction is a function that determines whether early termination was requested by the user

Functions

func CopyFile

func CopyFile(source, destination string) error

CopyFile copies the contents of source into a new file in destination

func CountLines added in v0.2.0

func CountLines(content string) int

CountLines returns the number of lines in a string Ref: https://stackoverflow.com/a/24563853

func DirExists added in v0.2.0

func DirExists(dirPath string) bool

DirExists checks if dirPath is an actual directory in the local file system

func DownloadFile

func DownloadFile(URL string) (string, error)

DownloadFile downloads a file from an URL and saves it locally under destionationFilePath

func EnsureDir

func EnsureDir(dirName string) error

EnsureDir recursevily creates a directory tree if it doesn't exist already

func FileExists

func FileExists(filePath string) bool

FileExists checks if filePath is an actual file in the local file system

func IsEmpty

func IsEmpty(dir string) bool

IsEmpty tells whether a directory specified by "dir" is empty or not

func IsPackNameValid

func IsPackNameValid(packName string) bool

IsPackNameValid checks whether a pack name string matches specified regular expression.

func IsPackVendorNameValid

func IsPackVendorNameValid(vendorName string) bool

IsVendorNameValid checks whether a pack vendor name string matches specified regular expression.

func IsPackVersionValid

func IsPackVersionValid(packVersion string) bool

IsPackVersion checks whether a pack version string matches specified regular expression

func IsTerminalInteractive added in v0.2.0

func IsTerminalInteractive() bool

IsTerminalInteractive tells whether or not the current terminal is capable of complex interactions

func ListDir

func ListDir(dir, pattern string) ([]string, error)

ListDir generates a list of files and directories in "dir". If pattern is specified, generates a list with matches only. It does NOT walk subdirectories

func MoveFile

func MoveFile(source, destination string) error

MoveFile moves a file from one source to destination

func RandStringBytes

func RandStringBytes(n int) string

RandStringBytes returns a random string with n bytes long Ref: https://stackoverflow.com/a/31832326/3908350

func ReadXML

func ReadXML(path string, targetStruct interface{}) error

ReadXML reads in a file into an XML struct

func SecureCopy

func SecureCopy(dst io.Writer, src io.Reader) (int64, error)

SecureCopy avoids potential DoS vulnerabilities when downloading a stream from a remote origin or decompressing a file. Ref: G110: Potential DoS vulnerability via decompression bomb (https://cwe.mitre.org/data/definitions/409.html)

func SecureInflateFile

func SecureInflateFile(file *zip.File, destinationDir, stripPrefix string) error

SecureInflateFile avoids potentions file traversal vulnerabilities when inflating compressed files. It avoids extracting files with "../" if stripPrefix is provided, use that to strip file.Name files

func StartSignalWatcher added in v0.3.0

func StartSignalWatcher()

startSignalWatcher spins off a thread monitoring termination signals and retuns a function that returns whether termination was requested

func StopSignalWatcher added in v0.3.0

func StopSignalWatcher()

stopSignalWatcher sends a fake signal to the monitoring thread making it terminate

func TouchFile

func TouchFile(filePath string) error

TouchFile touches the file specified by filePath. If the file does not exist, create it. Touch also updates the modified timestamp of the file.

func WriteXML

func WriteXML(path string, targetStruct interface{}) error

WriteXML writes an XML struct to a file

Types

type PackInfo

type PackInfo struct {
	Location, Vendor, Pack, Version, Extension string
}

PackInfo defines a basic pack information set

func ExtractPackInfo

func ExtractPackInfo(packPath string, short bool) (PackInfo, error)

ExtractPackInfo takes in a path to a pack and extracts the needed information. It returns an error if any information is wrong Valid packPath's are: - /path/to/dev/Vendor.Pack.pdsc - /path/to/local/Vendor.Pack.Version.pack (or .zip) - https://web.com/Vendor.Pack.Version.pack (or .zip) If short is true, then prepare it considering that path is in the simpler form of Vendor.Pack[.x.y.z], used when removing packs/pdscs.

Jump to

Keyboard shortcuts

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