Documentation
¶
Index ¶
- Constants
- Variables
- func CopyFile(source, destination string) error
- func CountLines(content string) int
- func DirExists(dirPath string) bool
- func DownloadFile(URL string) (string, error)
- func EnsureDir(dirName string) error
- func FileExists(filePath string) bool
- func IsEmpty(dir string) bool
- func IsPackNameValid(packName string) bool
- func IsPackVendorNameValid(vendorName string) bool
- func IsPackVersionValid(packVersion string) bool
- func IsTerminalInteractive() bool
- func ListDir(dir, pattern string) ([]string, error)
- func MoveFile(source, destination string) error
- func RandStringBytes(n int) string
- func ReadXML(path string, targetStruct interface{}) error
- func SecureCopy(dst io.Writer, src io.Reader) (int64, error)
- func SecureInflateFile(file *zip.File, destinationDir string) error
- func TouchFile(filePath string) error
- func WriteXML(path string, targetStruct interface{}) error
- type PackInfo
Constants ¶
const DownloadBufferSize = 4096
DownloadBufferSize is the number of bytes to transfer from the stream to the downloaded file per iteration. It is 4kb
Variables ¶
var CacheDir string
CacheDir is used for cpackget to temporarily host downloaded pack files before moving it to CMSIS_PACK_ROOT
var HTTPClient *http.Client
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
Functions ¶
func CountLines ¶ added in v0.2.0
CountLines returns the number of lines in a string Ref: https://stackoverflow.com/a/24563853
func DirExists ¶ added in v0.2.0
DirExists checks if dirPath is an actual directory in the local file system
func DownloadFile ¶
DownloadFile downloads a file from an URL and saves it locally under destionationFilePath
func FileExists ¶
FileExists checks if filePath is an actual file in the local file system
func IsPackNameValid ¶
IsPackNameValid checks whether a pack name string matches specified regular expression.
func IsPackVendorNameValid ¶
IsVendorNameValid checks whether a pack vendor name string matches specified regular expression.
func IsPackVersionValid ¶
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 ¶
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 RandStringBytes ¶
RandStringBytes returns a random string with n bytes long Ref: https://stackoverflow.com/a/31832326/3908350
func SecureCopy ¶
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 ¶
SecureInflateFile avoids potentions file traversal vulnerabilities when inflating compressed files. It avoids extracting files with "../"
Types ¶
type PackInfo ¶
type PackInfo struct {
Location, Vendor, Pack, Version, Extension string
}
PackInfo defines a basic pack information set
func ExtractPackInfo ¶
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.