fileutil

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDirectoryMask = 0o755
)

Variables

View Source
var (
	ErrNotFile      = errors.New("path is not a file")
	ErrBadPath      = errors.New("bad path traversal blocked")
	ErrSymbolicLink = errors.New("symbolic links not supported")
	ErrInvalidPath  = errors.New("invalid path")
)

Functions

func FileExists added in v0.106.0

func FileExists(p string) (bool, error)

func FindInParents added in v0.105.0

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

FindInParents Returns the first occurrence of filename going up the dir tree

func IsCaseInsensitiveLocation added in v1.21.0

func IsCaseInsensitiveLocation(fs FS, dirPath string, warnFunc func(string)) (bool, error)

IsCaseInsensitiveLocation returns true if dirPath is a directory on a case-insensitive filesystem. dirPath must be writable. If it fails to delete the file, it uses warnFunc to emit a warning message.

func IsDir added in v0.105.0

func IsDir(p string) (bool, error)

IsDir Returns true if p is a directory, otherwise false

func IsDirEmpty added in v0.106.0

func IsDirEmpty(name string) (bool, error)

func PruneEmptyDirectories added in v0.106.0

func PruneEmptyDirectories(dirPath string) ([]string, error)

PruneEmptyDirectories iterates through the directory tree, removing empty directories, and directories that only contain empty directories.

func RemoveFile added in v0.106.0

func RemoveFile(p string) error

func VerifyAbsPath added in v0.106.0

func VerifyAbsPath(absPath, basePath string) error

func VerifyRelPath added in v0.106.0

func VerifyRelPath(relPath, basePath string) error

func VerifySafeFilename added in v0.106.0

func VerifySafeFilename(absPath string) error

VerifySafeFilename checks that the given file name is not a symbolic link and that the file name does not contain path traversal

Types

type FS added in v1.21.0

type FS interface {
	// Touch creates a file at path.
	Touch(path string) error
	// Exists returns true if there is a file at path.  It follows
	// symbolic links.
	Exists(path string) (bool, error)
	// Remove deletes the file at path.
	Remove(path string) error
}

FS is a tiny filesystem abstraction. The standard io/fs does not support any write operations, see https://github.com/golang/go/issues/45757.

func NewOSFS added in v1.21.0

func NewOSFS() FS

type OSFS added in v1.21.0

type OSFS struct{}

OSFS is the filesystem of the OS.

func (OSFS) Exists added in v1.21.0

func (OSFS) Exists(path string) (bool, error)

func (OSFS) Remove added in v1.21.0

func (OSFS) Remove(path string) error

func (OSFS) Touch added in v1.21.0

func (OSFS) Touch(path string) error

type RewindableReader

type RewindableReader interface {
	io.ReadSeeker
	// Rewind allows sets RewindableReader to start re-reading the same data.
	Rewind() error
	// Name returns a user-visible name for underlying storage.  It may help debug some issues.
	Name() string
}

RewindableReader allows repeatedly reading the same stream.

type WriterThenReader

type WriterThenReader interface {
	io.Writer
	// StartReading stops writing and returns a RewindableReader that will allow repeatedly
	// reading the data and the total length of data.  The WriterThenReader should be
	// discarded; calls to Write() after StartReading() will fail.
	StartReading() (RewindableReader, int64, error)
	// Name returns a user-visible name for underlying storage.  It may help debug some issues.
	Name() string
}

WriterThenReader writes data to storage, then allows reading it. It is suitable for repeatedly processing large volumes of data.

func NewFileWriterThenReader

func NewFileWriterThenReader(basename string) (WriterThenReader, error)

Jump to

Keyboard shortcuts

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