fileutil

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendStringToFile added in v1.21.5

func AppendStringToFile(path string, appendString string) error

AppendStringToFile takes a path to a file and a string to append and it appends it, returning err

func CanCreateSymlinks() bool

CanCreateSymlinks tests to see if it's possible to create a symlink

func CheckSignatureOrNoFile added in v1.21.5

func CheckSignatureOrNoFile(path string, signature string) error

CheckSignatureOrNoFile checks to make sure that a file or directory either doesn't exist or has #ddev-generated in its contents (so it can be overwritten) returns nil if overwrite is OK (if sig found or no file existing)

func CopyDir

func CopyDir(src string, dst string) error

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist. Symlinks are ignored and skipped. Credit @r0l1 https://gist.github.com/r0l1/92462b38df26839a3ca324697c8cba04

func CopyEmbedAssets added in v1.21.5

func CopyEmbedAssets(fsys embed.FS, sourceDir string, targetDir string) error

CopyEmbedAssets copies files in the named embed.FS sourceDir to the local targetDir (full path)

func CopyFile

func CopyFile(src string, dst string) error

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all its contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage. Credit @m4ng0squ4sh https://gist.github.com/m4ng0squ4sh/92462b38df26839a3ca324697c8cba04

func ExpandFilesAndDirectories added in v1.22.0

func ExpandFilesAndDirectories(dir string, paths []string) ([]string, error)

FindFilesInDirectory takes a list of files/directories and expands it into a a list of files only environment variables in list are expanded

func FgrepStringInFile

func FgrepStringInFile(fullPath string, needle string) (bool, error)

FgrepStringInFile is a small hammer for looking for a literal string in a file. It should only be used against very modest sized files, as the entire file is read into a string.

func FileExists

func FileExists(name string) bool

FileExists checks a file's existence

func FileHash added in v1.22.0

func FileHash(filePath string) (string, error)

FileHash returns string of hash of filePath passed in

func FileIsReadable added in v1.21.5

func FileIsReadable(name string) bool

FileIsReadable checks to make sure a file exists and is readable

func FindFilenameInDirectory added in v1.22.0

func FindFilenameInDirectory(basePath string, fileNames []string) (dirName string, err error)

FindFilenameInDirectory searches the basePath for files of a particular set of names Returns dirName found (can be "") and err

func GrepStringInFile added in v1.21.5

func GrepStringInFile(fullPath string, needle string) (bool, error)

GrepStringInFile is a small hammer for looking for a regex in a file. It should only be used against very modest sized files, as the entire file is read into a string.

func IsDirectory added in v1.21.5

func IsDirectory(path string) bool

IsDirectory returns true if path is a dir, false on error or not directory

func IsSameFile added in v1.21.5

func IsSameFile(path1 string, path2 string) (bool, error)

IsSameFile determines whether two paths refer to the same file/dir

func ListFilesInDir added in v0.15.0

func ListFilesInDir(path string) ([]string, error)

ListFilesInDir returns an array of files or directories found in a directory

func ListFilesInDirFullPath added in v1.21.5

func ListFilesInDirFullPath(path string) ([]string, error)

ListFilesInDirFullPath returns an array of full path of files found in a directory

func PurgeDirectory

func PurgeDirectory(path string) error

PurgeDirectory removes all of the contents of a given directory, leaving the directory itself intact.

func RandomFilenameBase added in v0.18.0

func RandomFilenameBase() string

RandomFilenameBase generates a temporary filename for use in testing or whatever. From https://stackoverflow.com/a/28005931/215713

func ReadFileIntoString added in v1.21.5

func ReadFileIntoString(path string) (string, error)

ReadFileIntoString just gets the contents of file into string

func RemoveContents added in v1.21.5

func RemoveContents(dir string) error

RemoveContents removes contents of passed directory From https://stackoverflow.com/questions/33450980/how-to-remove-all-contents-of-a-directory-using-golang

func ReplaceSimulatedLinks(path string)

ReplaceSimulatedLinks walks the path provided and tries to replace XSym links with real ones.

func ReplaceSimulatedXsymSymlinks(links []XSymContents) error

ReplaceSimulatedXsymSymlinks walks a list of XSymContents and makes real symlinks in their place. This is only valid on Windows host, only works with Docker for Windows (cifs filesystem)

func ReplaceStringInFile added in v1.4.0

func ReplaceStringInFile(searchString string, replaceString string, origPath string, destPath string) error

ReplaceStringInFile takes search and replace strings, an original path, and a dest path, returns error

func TemplateStringToFile added in v1.21.5

func TemplateStringToFile(content string, vars map[string]interface{}, targetFilePath string) error

TemplateStringToFile takes a template string, runs templ.Execute on it, and writes it out to file

Types

type XSymContents added in v1.21.5

type XSymContents struct {
	LinkLocation string
	LinkTarget   string
}
func FindSimulatedXsymSymlinks(basePath string) ([]XSymContents, error)

FindSimulatedXsymSymlinks searches the basePath provided for files whose first line is XSym, which is used in cifs filesystem for simulated symlinks.

Jump to

Keyboard shortcuts

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