fileutils

package
v1.48.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 21 Imported by: 129

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFile

func AppendFile(srcPath string, destFile *os.File) (err error)

Reads the content of the file in the source path and appends it to the file in the destination path.

func CleanOldDirs added in v0.13.0

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 CreateDirIfNotExist

func CreateDirIfNotExist(path string) error

func CreateFilePath

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

func CreateTempDir added in v0.3.3

func CreateTempDir() (string, error)

Creates the temp dir at tempDirBase. Set tempDirPath to the created directory path.

func CreateTempFile added in v0.13.0

func CreateTempFile() (*os.File, error)

Create a new temp file named "tempPrefix+timeStamp".

func FilesIdentical added in v0.13.0

func FilesIdentical(file1 string, file2 string) (bool, error)

Returns true if the two files have the same MD5 checksum.

func FindUpstream added in v0.3.2

func FindUpstream(itemToFInd string, itemType ItemType) (wd string, exists bool, err error)

Returns the path to the directory in which itemToFind is located. Traversing through directories from current work-dir to root. itemType determines whether looking for a file or dir.

func GetFileAndDirFromPath

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 GetFileInfo

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

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

func GetFileSeparator

func GetFileSeparator() string

func GetFileSize

func GetFileSize(file *os.File) (int64, error)

func GetHomeDir

func GetHomeDir() string

func GetLocalPathAndFile

func GetLocalPathAndFile(originalFileName, relativePath, targetPath string, flat bool, placeholdersUsed bool) (localTargetPath, fileName string)

Get the local path and filename from original file name and path according to targetPath

func GetTempDirBase added in v1.28.3

func GetTempDirBase() string

func GetUploadRequestContent

func GetUploadRequestContent(file *os.File) io.Reader

func IsDirEmpty added in v0.21.0

func IsDirEmpty(path string) (isEmpty bool, err error)

func IsDirExists

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

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

func IsEqualToLocalFile added in v0.14.1

func IsEqualToLocalFile(localFilePath, md5, sha1 string) (bool, error)

Compares provided Md5 and Sha1 to those of a local file.

func IsFileExists

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

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

func IsFileSymlink(file os.FileInfo) bool

func IsPathAccessible added in v1.44.2

func IsPathAccessible(path string) bool

Checks if the path is accessible.

func IsPathExists

func IsPathExists(path string, preserveSymLink bool) bool

Checks if the path exists. If path points at a symlink and `preserveSymLink == true`, function will return `true` regardless of the symlink target

func IsPathSymlink(path string) bool

func IsSshUrl

func IsSshUrl(urlPath string) bool

func JsonEqual added in v1.6.1

func JsonEqual(filePath1, filePath2 string) (isEqual bool, err error)

JSONEqual compares the JSON from two files.

func ListFiles

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

Return the list of files and directories in the specified path

func ListFilesRecursiveWalkIntoDirSymlink(path string, walkIntoDirSymlink bool) (fileList []string, err error)

Return the recursive list of files and directories in the specified path

func ListFilesWithFilterFunc added in v1.42.0

func ListFilesWithFilterFunc(rootPath string, isRecursive, walkIntoDirSymlink bool, filterFunc func(filePath string) (bool, error)) (fileList []string, err error)

Return the recursive list of files and directories in the specified path

func MoveDir added in v0.17.0

func MoveDir(fromPath, toPath string) error

Move directory content from one path to another.

func MoveFile added in v0.17.3

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 ReadFile

func ReadFile(filePath string) ([]byte, error)

func RemoveDirContents added in v1.7.0

func RemoveDirContents(dirPath string) (err error)

RemoveDirContents removes the contents of the directory, without removing the directory itself. If it encounters an error before removing all the files, it stops and returns that error.

func RemovePath added in v0.6.2

func RemovePath(testPath string) error

Removing the provided path from the filesystem

func RemoveTempDir

func RemoveTempDir(dirPath string) error

func RenamePath added in v0.6.2

func RenamePath(oldPath, newPath string) error

Renaming from old path to new path.

func SetTempDirBase added in v0.3.3

func SetTempDirBase(dirPath string)

Change the containing directory of temp dir.

func ZipFolderFiles

func ZipFolderFiles(source, target string) (err error)

Types

type FileDetails

type FileDetails struct {
	Checksum entities.Checksum
	Size     int64
}

func GetFileDetails

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

func GetFileDetailsFromReader added in v0.20.1

func GetFileDetailsFromReader(reader io.Reader, includeChecksums bool) (details *FileDetails, err error)

type ItemType added in v0.3.2

type ItemType string
const (
	SymlinkFileContent          = ""
	File               ItemType = "file"
	Dir                ItemType = "dir"
	Any                ItemType = "any"
)

Jump to

Keyboard shortcuts

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