utils

package
v1.9.26 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 26 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShortWrite = errors.New("short write")

Functions

func AsyncMultiWriter added in v0.1.5

func AsyncMultiWriter(writers ...io.Writer) io.Writer

AsyncMultiWriter creates a writer that duplicates its writes to all the provided writers asynchronous

func CalcChecksums added in v0.1.5

func CalcChecksums(reader io.Reader, checksumType ...Algorithm) (map[Algorithm]string, error)

CalcChecksums calculates all hashes at once using AsyncMultiWriter. The file is therefore read only once.

func CalcChecksumsBytes added in v1.9.24

func CalcChecksumsBytes(reader io.Reader, checksumType ...Algorithm) (map[Algorithm][]byte, error)

CalcChecksumsBytes calculates hashes like `CalcChecksums`, returns result as bytes

func CleanOldDirs added in v0.1.5

func CleanOldDirs() error

Old runs/tests may leave junk at temp dir. Each temp file/Dir is named with prefix+timestamp, search for all temp files/dirs that match the common prefix and validate their timestamp.

func CopyDir added in v1.0.0

func CopyDir(fromPath, toPath string, includeDirs bool, excludeNames []string) error

Copy directory content from one path to another. includeDirs means to copy also the dirs if presented in the src folder. excludeNames - Skip files/dirs in the src folder that match names in provided slice. ONLY excludes first layer (only in src folder).

func CopyFile added in v1.0.0

func CopyFile(dst, src string) (err error)

func CreateDirIfNotExist added in v1.0.0

func CreateDirIfNotExist(path string) error

func CreateExtractorPropsFile

func CreateExtractorPropsFile(extractorConfPath, buildInfoPath, buildName, buildNumber string, buildTimestamp time.Time, project string, configProperties map[string]string) (string, error)

Save all the extractor's properties into a local file. extractorConfPath - Path to a file to which all the extractor's properties will be written. buildInfoPath - Path to a file to which the build-info data will be written. buildName - Build name of the current build. buildNumber - Build number of the current build. project - JFrog Project key of the current build configProperties - Data of the actual extractor's properties. Returns the extractor Config file path.

func CreateFilePath added in v1.0.0

func CreateFilePath(localPath, fileName string) (string, error)

func CreateTempBuildFile

func CreateTempBuildFile(buildName, buildNumber, projectKey, buildsDirPath string, logger Log) (*os.File, error)

Create a temp file of build-info.

func CreateTempDir added in v0.1.5

func CreateTempDir() (string, error)

CreateTempDir creates a temporary directory and returns its path.

func DoubleWinPathSeparator

func DoubleWinPathSeparator(filePath string) string

func DownloadDependencies

func DownloadDependencies(downloadTo, filename, relativeFilePath string, downloadExtractorFunc func(downloadTo, downloadPath string) error, logger Log) error

func DownloadFile

func DownloadFile(downloadTo string, fromUrl string) (err error)

func FindFileInDirAndParents added in v1.0.0

func FindFileInDirAndParents(dirPath, fileName string) (string, error)

FindFileInDirAndParents looks for a file named fileName in dirPath and its parents, and returns the path of the directory where it was found. dirPath must be a full path.

func GetBuildDir

func GetBuildDir(buildName, buildNumber, projectKey, buildsDirPath string) (string, error)

func GetCachePath added in v0.1.5

func GetCachePath() (string, error)

GetCachePath returns the location of downloads dir inside the GOMODCACHE

func GetDependenciesGraph added in v0.1.5

func GetDependenciesGraph(projectDir string, log Log) (map[string][]string, error)

Runs 'go mod graph' command and returns map that maps dependencies to their child dependencies slice

func GetDependenciesList added in v0.1.5

func GetDependenciesList(projectDir string, log Log) (map[string]bool, error)

Runs go list -f {{with .Module}}{{.Path}}:{{.Version}}{{end}} all command and returns map of the dependencies

func GetFileAndDirFromPath added in v1.0.0

func GetFileAndDirFromPath(path string) (fileName, dir string)

Return the file's name and dir of a given path by finding the index of the last separator in the path. Support separators : "/" , "\\" and "\\\\"

func GetFileChecksums added in v0.1.5

func GetFileChecksums(filePath string, checksumType ...Algorithm) (checksums map[Algorithm]string, err error)

func GetFileContentAndInfo added in v0.1.5

func GetFileContentAndInfo(filePath string) (fileContent []byte, fileInfo os.FileInfo, err error)

func GetFileInfo added in v1.0.0

func GetFileInfo(path string, followSymlink bool) (fileInfo os.FileInfo, err error)

Get the file info of the file in path. If path points at a symlink and `followSymlink == false`, return the file info of the symlink instead

func GetFileSeparator added in v1.0.0

func GetFileSeparator() string

func GetGoModCachePath added in v0.1.5

func GetGoModCachePath() (string, error)

GetGoModCachePath returns the location of the go module cache

func GetModuleNameByDir added in v0.1.5

func GetModuleNameByDir(projectDir string, log Log) (string, error)

Runs 'go list -m' command and returns module name

func GetParsedGoVersion added in v1.8.5

func GetParsedGoVersion() (*version.Version, error)

func GetPartialsBuildDir

func GetPartialsBuildDir(buildName, buildNumber, projectKey, buildsDirPath string) (string, error)

func GetProjectRoot added in v0.1.5

func GetProjectRoot() (string, error)

Returns the root dir where the go.mod located.

func GetRegExp added in v1.3.0

func GetRegExp(regex string) (*regexp.Regexp, error)

func IsDirExists

func IsDirExists(path string, followSymlink bool) (bool, error)

Check if path points at a directory. If path points at a symlink and `followSymlink == false`, function will return `false` regardless of the symlink target

func IsFileExists

func IsFileExists(path string, followSymlink bool) (bool, error)

Check if path points at a file. If path points at a symlink and `followSymlink == false`, function will return `true` regardless of the symlink target

func IsFileSymlink(file os.FileInfo) bool

func IsLinux added in v1.3.0

func IsLinux() bool

func IsPathExists

func IsPathExists(path string) bool

IsPathExists checks if a path exists.

func IsPathSymlink(path string) bool

func IsWindows added in v1.3.0

func IsWindows() bool

func ListFiles

func ListFiles(path string, includeDirs bool) ([]string, error)

Return the list of files and directories in the specified path

func ListFilesByFilterFunc added in v1.3.0

func ListFilesByFilterFunc(path string, filterFunc func(filePath string) (bool, error)) ([]string, error)

Return all files in the specified path who satisfy the filter func. Not recursive.

func MoveDir added in v1.0.0

func MoveDir(fromPath, toPath string) error

Move directory content from one path to another.

func MoveFile added in v1.0.0

func MoveFile(sourcePath, destPath string) (err error)

GoLang: os.Rename() give error "invalid cross-device link" for Docker container with Volumes. MoveFile(source, destination) will work moving file between folders Therefore, we are using our own implementation (MoveFile) in order to rename files.

func NewDefaultLogger

func NewDefaultLogger(logLevel LevelType) *defaultLogger

NewDefaultLogger creates a new logger with a given LogLevel. All logs are written to Stderr and output is written to Stdout.

func ReadNLines added in v1.1.0

func ReadNLines(path string, total int) (lines []string, err error)

strip '\n' or read until EOF, return error if read error readNLines reads up to 'total' number of lines separated by \n.

func RemoveTempDir added in v0.1.5

func RemoveTempDir(dirPath string) error

func RunGo added in v0.1.5

func RunGo(goArg []string, repoUrl string) error

func UnixToWinPathSeparator added in v1.3.0

func UnixToWinPathSeparator(filePath string) string

func Unmarshal added in v1.1.0

func Unmarshal(filePath string, loadTarget interface{}) (err error)

Parses the JSON-encoded data and stores the result in the value pointed to by 'loadTarget'. filePath - Path to json file. loadTarget - Pointer to a struct

func WinToUnixPathSeparator added in v1.3.0

func WinToUnixPathSeparator(filePath string) string

Types

type Algorithm added in v0.1.5

type Algorithm int
const (
	MD5 Algorithm = iota
	SHA1
	SHA256
)

type FileDetails added in v1.3.0

type FileDetails struct {
	Checksum entities.Checksum
	Size     int64
}

func GetFileDetails added in v1.3.0

func GetFileDetails(filePath string, includeChecksums bool) (details *FileDetails, err error)

type LevelType

type LevelType int
const (
	ERROR LevelType = iota
	WARN
	INFO
	DEBUG
)

type Log

type Log interface {
	Debug(a ...interface{})
	Info(a ...interface{})
	Warn(a ...interface{})
	Error(a ...interface{})
	Output(a ...interface{})
}

type NullLog

type NullLog struct {
}

NullLog is a logger that does nothing

func (*NullLog) Debug

func (nl *NullLog) Debug(...interface{})

func (*NullLog) Error

func (nl *NullLog) Error(...interface{})

func (*NullLog) Info

func (nl *NullLog) Info(...interface{})

func (*NullLog) Output

func (nl *NullLog) Output(...interface{})

func (*NullLog) Warn

func (nl *NullLog) Warn(...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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