files

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCreateDir                    = "files.create_dir"
	ErrDeleteDir                    = "files.delete_dir"
	ErrReadFormFile                 = "files.read_form_file"
	ErrCreateFile                   = "files.create_file"
	ErrReadDir                      = "files.read_dir"
	ErrReadFile                     = "files.read_file"
	ErrFileAlreadyExists            = "files.file_already_exists"
	ErrInsufficientMemoryToReadFile = "files.insufficient_memory_to_read_file"
	ErrFileSizeLimit                = "files.file_size_limit"
	ErrProjectSizeLimit             = "files.project_size_limit"
	ErrUnexpected                   = "files.unexpected"
	ErrFileDoesNotExist             = "files.file_does_not_exist"
	ErrDirDoesNotExist              = "files.dir_does_not_exist"
	ErrNotAFile                     = "files.not_a_file"
	ErrNotADir                      = "files.not_a_dir"
)

Variables

This section is empty.

Functions

func CheckDir added in v0.4.0

func CheckDir(dirPath string) error

CheckDir returns nil if the path is a directory

func CheckDirErrPath added in v0.10.0

func CheckDirErrPath(dirPath string, errMsgPath string) error

CheckDir returns nil if the path is a directory

func CheckFile added in v0.4.0

func CheckFile(path string) error

CheckFile returns nil if the path is a file

func CheckFileErrPath added in v0.10.0

func CheckFileErrPath(path string, errMsgPath string) error

CheckFile returns nil if the path is a file

func Clean added in v0.20.0

func Clean(path string) (string, error)

e.g. ~/path/../path2 -> /home/ubuntu/path2 returns without escaping tilde if there was an error

func CloseSilent

func CloseSilent(closer io.Closer, closers ...io.Closer)

func CopyDirOverwrite added in v0.16.0

func CopyDirOverwrite(src string, dest string, ignoreFns ...IgnoreFn) error

func CopyFileOverwrite added in v0.16.0

func CopyFileOverwrite(src string, dest string) error

func CopyRecursiveShell added in v0.16.0

func CopyRecursiveShell(src string, dest string) error

func Create added in v0.16.0

func Create(path string) (*os.File, error)

the returned file should be closed by the caller

func CreateDir added in v0.14.0

func CreateDir(path string) error

func CreateDirIfMissing

func CreateDirIfMissing(path string) (bool, error)

func CreateFile added in v0.4.0

func CreateFile(path string) error

func DeleteDir added in v0.14.0

func DeleteDir(path string) error

func DeleteDirIfPresent added in v0.14.0

func DeleteDirIfPresent(path string) (bool, error)

func Dir added in v0.19.0

func Dir(path string) string

Return the path to the directory containing the provided path (with a trailing slash)

func DirPathRelativeToCWD added in v0.13.0

func DirPathRelativeToCWD(absPath string) string

func DirPathRelativeToDir added in v0.19.0

func DirPathRelativeToDir(absPath string, dir string) string

func DirPaths

func DirPaths(paths []string, addTrailingSlash bool) []string

func ErrorCreateDir added in v0.4.0

func ErrorCreateDir(path string) error

func ErrorCreateFile added in v0.4.0

func ErrorCreateFile(path string) error

func ErrorDeleteDir added in v0.14.0

func ErrorDeleteDir(path string) error

func ErrorDirDoesNotExist added in v0.4.0

func ErrorDirDoesNotExist(path string) error

func ErrorFileAlreadyExists added in v0.4.0

func ErrorFileAlreadyExists(path string) error

func ErrorFileDoesNotExist added in v0.4.0

func ErrorFileDoesNotExist(path string) error

func ErrorFileSizeLimit added in v0.19.0

func ErrorFileSizeLimit(maxFileSizeBytes int64) error

func ErrorInsufficientMemoryToReadFile added in v0.19.0

func ErrorInsufficientMemoryToReadFile(fileSizeBytes, availableMemBytes int64) error

func ErrorNotADir added in v0.4.0

func ErrorNotADir(path string) error

func ErrorNotAFile added in v0.4.0

func ErrorNotAFile(path string) error

func ErrorProjectSizeLimit added in v0.19.0

func ErrorProjectSizeLimit(maxProjectSizeBytes int64) error

func ErrorReadDir added in v0.4.0

func ErrorReadDir(path string) error

func ErrorReadFile added in v0.4.0

func ErrorReadFile(path string) error

func ErrorReadFormFile added in v0.4.0

func ErrorReadFormFile(fileName string) error

func ErrorUnexpected added in v0.4.0

func ErrorUnexpected() error

func EscapeTilde added in v0.14.0

func EscapeTilde(path string) (string, error)

e.g. ~/path -> /home/ubuntu/path returns original path if there was an error

func FileTree

func FileTree(paths []string, cwd string, dirsOrder DirsOrder) string

func FilterPathsWithDirPrefix added in v0.24.0

func FilterPathsWithDirPrefix(paths []string, prefix string) []string

func GetTopLevelDirectory added in v0.35.0

func GetTopLevelDirectory(path string) string

e.g. /home/ubuntu/path -> / or e.g. home/ubuntu/path -> home

func HashDirectory added in v0.16.0

func HashDirectory(dir string, ignoreFns ...IgnoreFn) (string, error)

func HashFile added in v0.16.0

func HashFile(path string, paths ...string) (string, error)

func IgnoreCortexDebug added in v0.12.0

func IgnoreCortexDebug(path string, fi os.FileInfo) (bool, error)

func IgnoreCortexYAML added in v0.8.0

func IgnoreCortexYAML(path string, fi os.FileInfo) (bool, error)

func IgnoreHiddenFiles

func IgnoreHiddenFiles(path string, fi os.FileInfo) (bool, error)

func IgnoreHiddenFolders

func IgnoreHiddenFolders(path string, fi os.FileInfo) (bool, error)

func IgnoreNonPython

func IgnoreNonPython(path string, fi os.FileInfo) (bool, error)

func IgnoreNonYAML

func IgnoreNonYAML(path string, fi os.FileInfo) (bool, error)

func IgnorePythonGeneratedFiles

func IgnorePythonGeneratedFiles(path string, fi os.FileInfo) (bool, error)

func IsAbsOrTildePrefixed added in v0.19.0

func IsAbsOrTildePrefixed(path string) bool

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(path string) bool

func IsFileOrDir

func IsFileOrDir(path string) bool

func IsFilePathPython

func IsFilePathPython(path string) bool

func IsFilePathYAML

func IsFilePathYAML(path string) bool

func ListDir

func ListDir(dir string, relative bool) ([]string, error)

func ListDirRecursive

func ListDirRecursive(dir string, relative bool, ignoreFns ...IgnoreFn) ([]string, error)

func LongestCommonPath added in v0.22.0

func LongestCommonPath(paths ...string) string

Retrieves the longest common path given a list of paths.

func MakeEmptyFile

func MakeEmptyFile(path string) error

func MakeEmptyFiles

func MakeEmptyFiles(path string, paths ...string) error

func MakeEmptyFilesInDir

func MakeEmptyFilesInDir(dir string, path string, paths ...string) error

func Open added in v0.4.0

func Open(path string) (*os.File, error)

the returned file should be closed by the caller

func OpenFile added in v0.4.0

func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

the returned file should be closed by the caller

func ParentDir

func ParentDir(dir string) string

func PathRelativeToCWD added in v0.13.0

func PathRelativeToCWD(absPath string) string

func PathRelativeToDir added in v0.19.0

func PathRelativeToDir(absPath string, dir string) string

func ReadFile added in v0.12.0

func ReadFile(path string) (string, error)

func ReadFileBytes added in v0.4.0

func ReadFileBytes(path string) ([]byte, error)

func ReadFileBytesErrPath added in v0.10.0

func ReadFileBytesErrPath(path string, errMsgPath string) ([]byte, error)

func ReadReqFile

func ReadReqFile(r *http.Request, fileName string) ([]byte, error)

ReadReqFile returns nil if no file

func RelToAbsPath added in v0.13.0

func RelToAbsPath(relativePath string, baseDir string) string

func ReplacePathWithTilde added in v0.14.1

func ReplacePathWithTilde(absPath string) string

e.g. /home/ubuntu/path -> ~/path

func SearchForFile

func SearchForFile(filename string, dir string) (string, error)

func SortFilePaths

func SortFilePaths(paths []string, dirsOrder DirsOrder) []string

func TmpDir

func TmpDir() (string, error)

func TrimDirPrefix

func TrimDirPrefix(fullPath string, dirPath string) string

func UserRelToAbsPath added in v0.13.0

func UserRelToAbsPath(relativePath string) string

func WriteFile added in v0.4.0

func WriteFile(data []byte, path string) error

func WriteFileFromReader added in v0.20.0

func WriteFileFromReader(reader io.Reader, path string) error

Types

type DirsOrder

type DirsOrder string
var DirsOnBottom DirsOrder = "bottom"
var DirsOnTop DirsOrder = "top"
var DirsSorted DirsOrder = "sorted"

type IgnoreFn

type IgnoreFn func(string, os.FileInfo) (bool, error)

IgnoreFn if passed a dir, returning true will ignore all subdirs of dir

func ErrorOnBigFilesFn added in v0.19.0

func ErrorOnBigFilesFn(maxFileSizeBytes int64) IgnoreFn

func ErrorOnProjectSizeLimit added in v0.19.0

func ErrorOnProjectSizeLimit(maxProjectSizeBytes int64) IgnoreFn

func GitIgnoreFn added in v0.14.0

func GitIgnoreFn(gitIgnorePath string) (IgnoreFn, error)

func IgnoreSpecificFiles added in v0.13.0

func IgnoreSpecificFiles(absPaths ...string) IgnoreFn

func PromptForFilesAboveSize added in v0.13.0

func PromptForFilesAboveSize(size int, promptMsgTemplate string) IgnoreFn

promptMsgTemplate should have two placeholders: the first is for the file path and the second is for the file size

Jump to

Keyboard shortcuts

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