fileutil

package
v1.16.4 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: GPL-2.0, GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxSafeNameLength is the maximum length of a safe filename
	MaxSafeNameLength = 100
)

Variables

View Source
var (
	ErrUnexpectedEOF         = errors.New("unexpected end of input after escape character")
	ErrUnknownEscapeSequence = errors.New("unknown escape sequence")
)
View Source
var ValidYAMLExtensions = []string{yamlExtension, ymlExtension}

ValidYAMLExtensions contains valid YAML extensions.

Functions

func EnsureYAMLExtension

func EnsureYAMLExtension(filename string) string

EnsureYAMLExtension adds .yaml extension if not present if it has .yml extension, replace it with .yaml

func FileExists

func FileExists(file string) bool

FileExists returns true if file exists.

func IsDir

func IsDir(path string) bool

IsDir returns true if path is a directory.

func IsFileWithExtension

func IsFileWithExtension(filename string, validExtensions []string) bool

IsFileWithExtension is a more generic function that checks if a file has any of the provided extensions.

func IsYAMLFile

func IsYAMLFile(filename string) bool

IsYAMLFile checks if a file has a valid YAML extension (.yaml or .yml). Returns false for empty strings or files without extensions.

func MustGetUserHomeDir

func MustGetUserHomeDir() string

MustGetUserHomeDir returns current working directory. Panics is os.UserHomeDir() returns error

func MustGetwd

func MustGetwd() string

MustGetwd returns current working directory. Panics is os.Getwd() returns error

func MustTempDir

func MustTempDir(pattern string) string

MustTempDir returns temporary directory. This function is used only for testing.

func OpenOrCreateFile

func OpenOrCreateFile(file string) (*os.File, error)

OpenOrCreateFile opens file or creates it if it doesn't exist.

func SafeName

func SafeName(str string) string

SafeName converts a string to a safe filename

func TruncString

func TruncString(val string, max int) string

TruncString TurnString returns truncated string.

Types

type FileNotFoundError

type FileNotFoundError struct {
	Path          string
	SearchedPaths []string
}

FileNotFoundError provides detailed information about file search failure

func (*FileNotFoundError) Error

func (e *FileNotFoundError) Error() string

type FileResolver

type FileResolver struct {
	// contains filtered or unexported fields
}

FileResolver handles file path resolution across multiple locations

func NewFileResolver

func NewFileResolver(relativeTos []string) *FileResolver

NewFileResolver creates a new FileResolver instance

func (*FileResolver) ResolveFilePath

func (r *FileResolver) ResolveFilePath(file string) (string, error)

ResolveFilePath attempts to find a file in multiple locations in the following order: 1. As an absolute path 2. Relative to the DAG directory 3. Relative to the base config directory 4. Relative to the user's home directory

Jump to

Keyboard shortcuts

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