os

package
v0.0.0-...-40387b0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: LGPL-2.1 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
	O_RDONLY int = syscall.O_RDONLY // open the file read-only.
	O_WRONLY int = syscall.O_WRONLY // open the file write-only.
	O_RDWR   int = syscall.O_RDWR   // open the file read-write.
	// The remaining values may be or'ed in to control behavior.
	O_APPEND int = syscall.O_APPEND // append data to the file when writing.
	O_CREATE int = syscall.O_CREAT  // create a new file if none exists.
	O_EXCL   int = syscall.O_EXCL   // used with O_CREATE, file must not exist.
	O_SYNC   int = syscall.O_SYNC   // open for synchronous I/O.
	O_TRUNC  int = syscall.O_TRUNC  // truncate regular writable file when opened.
)
View Source
const (
	SEEK_SET int = 0 // seek relative to the origin of the file
	SEEK_CUR int = 1 // seek relative to the current offset
	SEEK_END int = 2 // seek relative to the end
)
View Source
const (
	PathSeparator     = '/' // OS-specific path separator
	PathListSeparator = ':' // OS-specific path list separator
)
View Source
const (
	// The single letters are the abbreviations
	// used by the String method's formatting.
	ModeDir        = fs.ModeDir        // d: is a directory
	ModeAppend     = fs.ModeAppend     // a: append-only
	ModeExclusive  = fs.ModeExclusive  // l: exclusive use
	ModeTemporary  = fs.ModeTemporary  // T: temporary file; Plan 9 only
	ModeSymlink    = fs.ModeSymlink    // L: symbolic link
	ModeDevice     = fs.ModeDevice     // D: device file
	ModeNamedPipe  = fs.ModeNamedPipe  // p: named pipe (FIFO)
	ModeSocket     = fs.ModeSocket     // S: Unix domain socket
	ModeSetuid     = fs.ModeSetuid     // u: setuid
	ModeSetgid     = fs.ModeSetgid     // g: setgid
	ModeCharDevice = fs.ModeCharDevice // c: Unix character device, when ModeDevice is set
	ModeSticky     = fs.ModeSticky     // t: sticky
	ModeIrregular  = fs.ModeIrregular  // ?: non-regular file; nothing else is known about this file

	// Mask for the type bits. For regular files, none will be set.
	ModeType = fs.ModeType

	ModePerm = fs.ModePerm // Unix permission bits, 0o777
)

Variables

View Source
var (
	// ErrInvalid indicates an invalid argument.
	// Methods on File will return this error when the receiver is nil.
	ErrInvalid = oos.ErrInvalid // "invalid argument"

	ErrPermission = oos.ErrPermission // "permission denied"
	ErrExist      = oos.ErrExist      // "file already exists"
	ErrNotExist   = oos.ErrNotExist   // "file does not exist"
	ErrClosed     = oos.ErrClosed     // "file already closed"

	ErrNoDeadline       = oos.ErrNoDeadline       // "file type does not support deadline"
	ErrDeadlineExceeded = oos.ErrDeadlineExceeded // "i/o timeout"
)
View Source
var (
	Stdin  = oos.Stdin
	Stdout = oos.Stdout
	Stderr = oos.Stderr
)
View Source
var (
	ErrFileClosed   = afero.ErrFileClosed
	ErrOutOfRange   = afero.ErrOutOfRange
	ErrTooLarge     = afero.ErrTooLarge
	ErrNotSupported = errors.New("not supported in virtual mode")
)
View Source
var Args []string
View Source
var ErrProcessDone = oos.ErrProcessDone

Functions

func Chdir

func Chdir(dir string) error

func Chmod

func Chmod(name string, mode FileMode) error

func Chown

func Chown(name string, uid, gid int) error

func Chtimes

func Chtimes(name string, atime time.Time, mtime time.Time) error

func Clearenv

func Clearenv()

Clearenv deletes all environment variables.

func DirFS

func DirFS(dir string) fs.FS

func Environ

func Environ() []string

Environ returns a copy of strings representing the environment, in the form "key=value".

func Executable

func Executable() (string, error)

func Exit

func Exit(code int)

func Expand

func Expand(s string, mapping func(string) string) string

func ExpandEnv

func ExpandEnv(s string) string

ExpandEnv replaces ${var} or $var in the string according to the values of the current environment variables. References to undefined variables are replaced by the empty string.

func Getegid

func Getegid() int

func Getenv

func Getenv(key string) string

Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present. To distinguish between an empty value and an unset value, use LookupEnv.

func Geteuid

func Geteuid() int

func Getgid

func Getgid() int

func Getgroups

func Getgroups() ([]int, error)

func Getpagesize

func Getpagesize() int

func Getpid

func Getpid() int

func Getppid

func Getppid() int

func Getuid

func Getuid() int

func Getwd

func Getwd() (string, error)

func Hostname

func Hostname() (string, error)

func IsExist

func IsExist(err error) bool

IsExist returns a boolean indicating whether the error is known to report that a file or directory already exists. It is satisfied by ErrExist as well as some syscall errors.

This function predates errors.Is. It only supports errors returned by the os package. New code should use errors.Is(err, fs.ErrExist).

func IsNotExist

func IsNotExist(err error) bool

IsNotExist returns a boolean indicating whether the error is known to report that a file or directory does not exist. It is satisfied by ErrNotExist as well as some syscall errors.

This function predates errors.Is. It only supports errors returned by the os package. New code should use errors.Is(err, fs.ErrNotExist).

func IsPathSeparator

func IsPathSeparator(c uint8) bool

func IsPermission

func IsPermission(err error) bool

IsPermission returns a boolean indicating whether the error is known to report that permission is denied. It is satisfied by ErrPermission as well as some syscall errors.

This function predates errors.Is. It only supports errors returned by the os package. New code should use errors.Is(err, fs.ErrPermission).

func IsTimeout

func IsTimeout(err error) bool

IsTimeout returns a boolean indicating whether the error is known to report that a timeout occurred.

This function predates errors.Is, and the notion of whether an error indicates a timeout can be ambiguous. For example, the Unix error EWOULDBLOCK sometimes indicates a timeout and sometimes does not. New code should use errors.Is with a value appropriate to the call returning the error, such as os.ErrDeadlineExceeded.

func Lchown

func Lchown(name string, uid, gid int) error
func Link(oldname, newname string) error

func LookupEnv

func LookupEnv(key string) (string, bool)

LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

func Mkdir

func Mkdir(name string, perm FileMode) error

func MkdirAll

func MkdirAll(path string, perm FileMode) error

func MkdirTemp

func MkdirTemp(dir, pattern string) (string, error)

func NewSyscallError

func NewSyscallError(syscall string, err error) error

func Pipe

func Pipe() (*oos.File, *oos.File, error)

func ReadFile

func ReadFile(name string) ([]byte, error)
func Readlink(name string) (string, error)

func Remove

func Remove(name string) error

func RemoveAll

func RemoveAll(path string) error

func Rename

func Rename(oldpath, newpath string) error

func SameFile

func SameFile(fi1, fi2 FileInfo) bool

func Setenv

func Setenv(key, value string) error

Setenv sets the value of the environment variable named by the key. It returns an error, if any.

func Symlink(oldname, newname string) error

func TempDir

func TempDir() string

TempDir returns the default directory to use for temporary files.

On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows, it uses GetTempPath, returning the first non-empty value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. On Plan 9, it returns /tmp.

The directory is neither guaranteed to exist nor have accessible permissions.

func Truncate

func Truncate(name string, size int64) error

func Unsetenv

func Unsetenv(key string) error

Unsetenv unsets a single environment variable.

func UserCacheDir

func UserCacheDir() (string, error)

UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own application-specific subdirectory within this one and use that.

On Unix systems, it returns $XDG_CACHE_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache.

If the location cannot be determined (for example, $HOME is not defined), then it will return an error.

func UserConfigDir

func UserConfigDir() (string, error)

UserConfigDir returns the default root directory to use for user-specific configuration data. Users should create their own application-specific subdirectory within this one and use that.

On Unix systems, it returns $XDG_CONFIG_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.config. On Darwin, it returns $HOME/Library/Application Support. On Windows, it returns %AppData%. On Plan 9, it returns $home/lib.

If the location cannot be determined (for example, $HOME is not defined), then it will return an error.

func UserHomeDir

func UserHomeDir() (string, error)

UserHomeDir returns the current user's home directory.

On Unix, including macOS, it returns the $HOME environment variable. On Windows, it returns %USERPROFILE%. On Plan 9, it returns the $home environment variable.

func WriteFile

func WriteFile(name string, data []byte, perm FileMode) error

Types

type DirEntry

type DirEntry oos.DirEntry

type File

type File afero.File

type FileInfo

type FileInfo oos.FileInfo

type FileMode

type FileMode oos.FileMode

type LinkError

type LinkError oos.LinkError

type PathError

type PathError oos.PathError

type ProcAttr

type ProcAttr oos.ProcAttr

type Process

type Process oos.Process

type ProcessState

type ProcessState oos.ProcessState

type Signal

type Signal oos.Signal

type SyscallError

type SyscallError oos.SyscallError

Jump to

Keyboard shortcuts

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