osext

package
v3.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package osext provides some helpful os functions.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotADir = errors.New("not a directory")

ErrNotADir is returned when the path is not a directory.

Functions

func Caller

func Caller(steps int) string

func DirExists

func DirExists(dir string) error

DirExists checks if the directory exists and is a directory. It will return an error if the path does not exist, and if the path is not a directory, ErrNotADir will be returned.

func IsDocker added in v3.0.7

func IsDocker() bool

IsDocker returns true if the process is running in a docker container.

func IsInteractive added in v3.0.7

func IsInteractive() bool

isInteractive returns true if the program is running in the interactive terminal.

func IsPathError

func IsPathError(err error) bool

IsPathError reports whether the error is an fs.PathError.

func IsRoot added in v3.0.7

func IsRoot() bool

func IsSame

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

IsSame returns true if path1 and path2 both pointing to the same object.

func MoveFile

func MoveFile(src string, fs fsadapter.FS, dst string) error

MoveFile moves a file from src to dst. If dst already exists, it will be overwritten.

Adopted solution from https://stackoverflow.com/questions/50740902/move-a-file-to-a-different-drive-with-go

func UnGZIP

func UnGZIP(r io.Reader) (*os.File, error)

UnGZIP decompresses a gzip file and returns a temporary file handler. it must be removed after use. It expects r to contain a gzip file data.

Types

type Error

type Error struct {
	File string
	Err  error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Namer

type Namer interface {
	// Name should return the name of the file.  *os.File implements this
	// interface.
	Name() string
}

Namer is an interface that allows us to get the name of the file.

type ReadSeekCloseNamer

type ReadSeekCloseNamer interface {
	io.ReadSeekCloser
	Name() string
}

ReadSeekCloseNamer is an io.ReadSeekCloser that also has a Name method.

func RemoveOnClose

func RemoveOnClose(r *os.File) ReadSeekCloseNamer

RemoveOnClose wraps an *os.File and removes it when it is closed. The filename must be given.

type RemoveWrapper

type RemoveWrapper struct {
	io.ReadSeekCloser
	// contains filtered or unexported fields
}

RemoveWrapper wraps an io.ReadSeekCloser and removes the file when it is closed.

func (RemoveWrapper) Close

func (r RemoveWrapper) Close() error

func (RemoveWrapper) Name

func (r RemoveWrapper) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳