utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: Apache-2.0 Imports: 30 Imported by: 39

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 CalculateDependenciesList added in v1.0.0

func CalculateDependenciesList(typeRestriction TypeRestriction, executablePath, srcPath, moduleId string, npmArgs []string, traverseDependenciesFunc func(dependency *entities.Dependency) (bool, error), threads int, log Log) (dependenciesList []entities.Dependency, err error)

CalculateDependenciesList gets an npm project's dependencies. It sends each of them as a parameter to traverseDependenciesFunc and based on its return values, they will be returned from CalculateDependenciesList.

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) error

func CreateDirIfNotExist added in v1.0.0

func CreateDirIfNotExist(path string) error

func CreateExtractorPropsFile

func CreateExtractorPropsFile(extractorConfPath, buildInfoPath, buildName, buildNumber, 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) (checksums *entities.Checksum, 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 GetNpmVersionAndExecPath added in v1.0.0

func GetNpmVersionAndExecPath(log Log) (*version.Version, string, 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 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 IsPathExists

func IsPathExists(path string) bool

IsPathExists checks if a path exists.

func IsPathSymlink(path string) bool

func IsStringInSlice added in v1.0.0

func IsStringInSlice(string string, strings []string) bool

func ListFiles

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

Return the list of files and directories in the specified path

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 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

Types

type Algorithm added in v0.1.5

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

type Cmd added in v0.1.5

type Cmd struct {
	Go           string
	Command      []string
	CommandFlags []string
	Dir          string
	StrWriter    io.WriteCloser
	ErrWriter    io.WriteCloser
}

func (*Cmd) GetCmd added in v0.1.5

func (config *Cmd) GetCmd() (cmd *exec.Cmd)

func (*Cmd) GetEnv added in v0.1.5

func (config *Cmd) GetEnv() map[string]string

func (*Cmd) GetErrWriter added in v0.1.5

func (config *Cmd) GetErrWriter() io.WriteCloser

func (*Cmd) GetStdWriter added in v0.1.5

func (config *Cmd) GetStdWriter() io.WriteCloser

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{})

type PackageInfo added in v1.0.0

type PackageInfo struct {
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
	Scope   string
}

func ReadPackageInfo added in v1.0.0

func ReadPackageInfo(data []byte, npmVersion *version.Version) (*PackageInfo, error)

func ReadPackageInfoFromPackageJson added in v1.0.0

func ReadPackageInfoFromPackageJson(packageJsonDirectory string, npmVersion *version.Version) (*PackageInfo, error)

func (*PackageInfo) BuildInfoModuleId added in v1.0.0

func (pi *PackageInfo) BuildInfoModuleId() string

func (*PackageInfo) FullName added in v1.0.0

func (pi *PackageInfo) FullName() string

func (*PackageInfo) GetDeployPath added in v1.0.0

func (pi *PackageInfo) GetDeployPath() string

type TypeRestriction added in v1.0.0

type TypeRestriction int
const (
	DefaultRestriction TypeRestriction = iota
	All
	DevOnly
	ProdOnly
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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