osutil

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 9 Imported by: 9

README

goulash/osutil

Package osutil provides utility functions especially related to interaction with the outside world, aka the operating system.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineCmdArgs

func CombineCmdArgs(args ...interface{}) []string

CombineCmdArgs puts the given arguments all in a slice. If one of the arguments is a string, then it is split by spaces, and if it is a slice, then the elements are added to the slice. This is all returned.

Warning: this is a very obscure and weird function (it's already bitten me once), so be careful.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile tries to copy src to dst. If dst already exists, it will be overwritten. If it does not exist, it will be created.

func CopyFileLazy

func CopyFileLazy(src, dst string) error

CopyFileLazy is the same as CopyFile, except that it avoids copying the file when the destination already has the same contents.

func DirExists

func DirExists(path string) (ex bool, err error)

DirExists returns ex = true if the file exists and is a directory, and returns err != nil if any other error occured (such as permission denied).

func Exists

func Exists(path string) (ex bool, err error)

Exists returns ex = true if the given file exists, regardless whether it is a file or a directory. Normally you will probably want to use the more specific versions: FileExists and DirectoryExists.

func FileExists

func FileExists(path string) (ex bool, err error)

FileExists returns ex = true if the file exists and is not a directory, and returns err != nil if any other error occured (such as permission denied).

func FileExt

func FileExt(filepath string) string

FileExt returns the file type as identified by the (lowercase) extension. As such it is very limited, but for limited purposes, simple enough.

func MoveFile

func MoveFile(src, dst string) error

MoveFile tries to move src to dst. If dst already exists, it will be overwritten.

func MoveFileLazy

func MoveFileLazy(src, dst string) error

MoveFileLazy is the same as MoveFile, except that it avoids copying the file when the destination already has the same contents.

func RunCmd

func RunCmd(cmd *exec.Cmd) bool

RunCmd runs the command and returns whether it completed correctly or not. If any error occurs, then the entire output is printed to the log file.

func SameContents

func SameContents(src, dst string) (same bool, err error)

SameContents returns same = true if src and dst both exist and have the same file contents. Whether the file data is at the same place on disk is a different question, which is not answered.

If either file is a directory, FileTypeError is returned.

func SameFile

func SameFile(src, dst string) (same bool, err error)

Types

type FileTypeError

type FileTypeError struct {
	Filepath string
}

func (FileTypeError) Error

func (e FileTypeError) Error() string

Jump to

Keyboard shortcuts

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