Documentation
¶
Index ¶
- Constants
- Variables
- func CheckConnection(url string, timeOut int) error
- 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, timeout int) (string, error)
- func EnsureDir(dirName string) error
- func FileExists(filePath string) bool
- func FilterPackID(content string, filter string) string
- func FormatPackVersion(pack []string) string
- func GetEncodedProgress() bool
- func GetSkipTouch() bool
- func IsBase64(s 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, stripPrefix string) error
- func SemverCompare(version1, version2 string) int
- func SemverMajor(version string) string
- func SetEncodedProgress(encodedProgress bool)
- func SetReadOnly(path string)
- func SetReadOnlyR(path string)
- func SetSkipTouch(skipTouch bool)
- func StartSignalWatcher()
- func StopSignalWatcher()
- func TouchFile(filePath string) error
- func UnsetReadOnly(path string)
- func UnsetReadOnlyR(path string)
- func WriteXML(path string, targetStruct interface{}) error
- type EncodedProgress
- type PackInfo
- type TimeoutTransport
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 // For the <package/requirements/packages> spec only. Example: Vendor.PackName.a.b.c:x.y.z RangeVersion = 5 )
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 ( // File RO (ReadOnly) and RW (Read + Write) modes FileModeRO = fs.FileMode(0444) FileModeRW = fs.FileMode(0666) // Directory RO (ReadOnly + Traverse) and RW (Read + Write + Traverse) modes DirModeRO = fs.FileMode(0555) DirModeRW = fs.FileMode(0777) )
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 CheckConnection ¶ added in v1.1.0
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 FormatPackVersion ¶ added in v0.9.2
FormatPackVersion returns a modern representation of an internally versioned pack (for dependencies). Example: CMSIS,ARM,5.6.0:_ -> ARM::CMSIS@>=5.6.0 Ref: https://github.com/Open-CMSIS-Pack/devtools/blob/main/tools/projmgr/docs/Manual/YML-Input-Format.md#pack-name-conventions
func GetEncodedProgress ¶ added in v1.0.0
func GetEncodedProgress() bool
func GetSkipTouch ¶ added in v1.0.0
func GetSkipTouch() bool
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 SemverCompare ¶ added in v0.6.0
SemverCompare extends `semver.Compare` to work with leading zeros
func SemverMajor ¶ added in v0.6.0
SemverMajor extends `semver.Major` to work with leading zeros
func SetEncodedProgress ¶ added in v1.0.0
func SetEncodedProgress(encodedProgress bool)
func SetReadOnly ¶ added in v0.7.0
func SetReadOnly(path string)
SetReadOnly takes in a file or directory and set it to read-only mode. Should work on both Windows and Linux.
func SetReadOnlyR ¶ added in v0.7.0
func SetReadOnlyR(path string)
SetReadOnlyR works the same as SetReadOnly, except that it is recursive
func SetSkipTouch ¶ added in v1.0.0
func SetSkipTouch(skipTouch bool)
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 ¶
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 UnsetReadOnly ¶ added in v0.7.0
func UnsetReadOnly(path string)
UnsetReadOnly takes in a file or directory and set it to read-only mode. Should work on both Windows and Linux.
func UnsetReadOnlyR ¶ added in v0.7.0
func UnsetReadOnlyR(path string)
UnsetReadOnlyR works the same as UnsetReadOnly, but recursive
Types ¶
type EncodedProgress ¶ added in v1.0.0
type EncodedProgress struct {
// contains filtered or unexported fields
}
func NewEncodedProgress ¶ added in v1.0.0
func NewEncodedProgress(max int64, instNo int, filename string) *EncodedProgress
func (*EncodedProgress) Add ¶ added in v1.0.0
func (p *EncodedProgress) Add(count int) int
func (*EncodedProgress) Print ¶ added in v1.0.0
func (p *EncodedProgress) Print()
Encodes information to show progress when called by GUI or other tools * I: Instance number (always counts up), connected to the filename * F: Filename currently processed * T: Total bytes of file or numbers of files * P: Currently processed percentage * C: Currently processed bytes or numbers of files * J: Total number of files beeing processed * L: License file follows * O: Online connection Status [offline|online]
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.