Documentation
¶
Index ¶
- Constants
- Variables
- func CleanPath(path string) string
- 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 FilterPackID(content string, filter string) string
- 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, stripPrefix string) error
- func StartSignalWatcher()
- func StopSignalWatcher()
- func TouchFile(filePath string) error
- func WriteXML(path string, targetStruct interface{}) error
- type PackInfo
Constants ¶
const ( // Examples: Vendor::PackName@x.y.z, Vendor.PackName.x.y.z ExactVersion int = 0 // Example: Vendor::PackName@latest LatestVersion = 1 // Examples: Vendor::PackName, Vendor.PackName AnyVersion = 2 // Example: Vendor::PackName>=x.y.z GreaterVersion = 3 // Example: Vendor::PackName@~x.y.z (the greatest version of the pack keeping the same major number) GreatestCompatibleVersion = 4 )
The version modifiers below are helpers to determine how to interpret the version specified by the packID.
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
var ShouldAbortFunction func() bool
ShouldAbortFunction is a function that determines whether early termination was requested by the user
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 FilterPackID ¶ added in v0.5.1
FilterPackId returns the original string if any of the received filter words are present - designed specifically to filter pack IDs
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 "../" 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
Types ¶
type PackInfo ¶
type PackInfo struct {
Location, Vendor, Pack, Version, Extension string
IsPackID bool
VersionModifier int
}
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. NOTE: a malformed packPath e.g. "my.pack" DOES look like a valid
pack name, with "my" for vendor and "pack" for pack name.