os

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 12 Imported by: 6

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.
)

Flags to OpenFile wrapping those of the underlying system. Not all flags may be implemented on a given system.

Variables

This section is empty.

Functions

func GetScriptArgs added in v1.1.0

func GetScriptArgs() []string

if risor is started from the command line and args are passed in, this is is how the to get them

func MassagePathError

func MassagePathError(basePath string, err error) error

MassagePathError transforms a fs.PathError into a new one with the base path removed from the Path field.

func ResolvePath

func ResolvePath(base, path, op string) (string, error)

ResolvePath resolves a path relative to a base path. An error is returned if the path is invalid.

func SetScriptArgs added in v1.1.0

func SetScriptArgs(args []string)

if risor is started from the command line and args are passed in, this is is how the to tell the os package about them

func WithOS

func WithOS(ctx context.Context, osObj OS) context.Context

WithOS adds an OS to the context. Subsequently, when this context is present in the invocation of Risor builtins, this OS will be used for all related functionality.

Types

type BufferFile added in v1.3.2

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

BufferFile is an in memory file backed by a bytes buffer Writes to this file are append only and seek is not supported

func NewBufferFile added in v1.3.2

func NewBufferFile(data []byte) *BufferFile

func (*BufferFile) Bytes added in v1.3.2

func (f *BufferFile) Bytes() []byte

func (*BufferFile) Close added in v1.3.2

func (f *BufferFile) Close() error

func (*BufferFile) Read added in v1.3.2

func (f *BufferFile) Read(p []byte) (n int, err error)

func (*BufferFile) ReadAt added in v1.3.2

func (f *BufferFile) ReadAt(p []byte, off int64) (n int, err error)

func (*BufferFile) Seek added in v1.3.2

func (f *BufferFile) Seek(offset int64, whence int) (int64, error)

func (*BufferFile) Stat added in v1.3.2

func (f *BufferFile) Stat() (FileInfo, error)

func (*BufferFile) Write added in v1.3.2

func (f *BufferFile) Write(p []byte) (n int, err error)

type DirEntry

type DirEntry interface {
	fs.DirEntry
	HasInfo() bool
}

type DirEntryWrapper

type DirEntryWrapper struct {
	fs.DirEntry
}

func (*DirEntryWrapper) HasInfo

func (de *DirEntryWrapper) HasInfo() bool

type ExitHandler

type ExitHandler func(int)

type FS

type FS interface {
	Create(name string) (File, error)
	Mkdir(name string, perm FileMode) error
	MkdirAll(path string, perm FileMode) error
	Open(name string) (File, error)
	OpenFile(name string, flag int, perm FileMode) (File, error)
	ReadFile(name string) ([]byte, error)
	Remove(name string) error
	RemoveAll(path string) error
	Rename(oldpath, newpath string) error
	Stat(name string) (FileInfo, error)
	Symlink(oldname, newname string) error
	WriteFile(name string, data []byte, perm FileMode) error
	ReadDir(name string) ([]DirEntry, error)
	WalkDir(root string, fn WalkDirFunc) error
}

type File

type File interface {
	fs.File
	io.Writer
}

type FileInfo

type FileInfo = fs.FileInfo

type FileMode

type FileMode = fs.FileMode

type GenericDirEntry

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

func NewDirEntry

func NewDirEntry(opts GenericDirEntryOpts) *GenericDirEntry

func (*GenericDirEntry) HasInfo

func (de *GenericDirEntry) HasInfo() bool

func (*GenericDirEntry) Info

func (de *GenericDirEntry) Info() (FileInfo, error)

func (*GenericDirEntry) IsDir

func (de *GenericDirEntry) IsDir() bool

func (*GenericDirEntry) Name

func (de *GenericDirEntry) Name() string

func (*GenericDirEntry) Type

func (de *GenericDirEntry) Type() FileMode

type GenericDirEntryOpts

type GenericDirEntryOpts struct {
	Name string
	Mode FileMode
	Info *GenericFileInfo
}

type GenericFileInfo

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

func NewFileInfo

func NewFileInfo(opts GenericFileInfoOpts) *GenericFileInfo

func (*GenericFileInfo) IsDir

func (fi *GenericFileInfo) IsDir() bool

func (*GenericFileInfo) ModTime

func (fi *GenericFileInfo) ModTime() time.Time

func (*GenericFileInfo) Mode

func (fi *GenericFileInfo) Mode() FileMode

func (*GenericFileInfo) Name

func (fi *GenericFileInfo) Name() string

func (*GenericFileInfo) Size

func (fi *GenericFileInfo) Size() int64

func (*GenericFileInfo) Sys

func (fi *GenericFileInfo) Sys() interface{}

type GenericFileInfoOpts

type GenericFileInfoOpts struct {
	Name    string
	Size    int64
	Mode    FileMode
	ModTime time.Time
	IsDir   bool
}

type InMemoryFile added in v0.10.0

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

InMemoryFile is an in-memory file backed by a slice of bytes with support for seek

func NewInMemoryFile added in v0.10.0

func NewInMemoryFile(data []byte) *InMemoryFile

func (*InMemoryFile) Bytes added in v0.10.0

func (b *InMemoryFile) Bytes() []byte

Bytes returns the underlying bytes from the current position.

func (*InMemoryFile) Close added in v0.10.0

func (f *InMemoryFile) Close() error

Close clears all the data out of the file and sets the read position to 0.

func (*InMemoryFile) Len added in v1.3.2

func (f *InMemoryFile) Len() int

Len returns the length of data remaining to be read.

func (*InMemoryFile) Read added in v0.10.0

func (f *InMemoryFile) Read(p []byte) (int, error)

Read reads the next len(p) bytes from the file or until the end is reached.

func (*InMemoryFile) ReadAt added in v0.10.0

func (f *InMemoryFile) ReadAt(p []byte, off int64) (int, error)

ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the read pointer is not modified.

func (*InMemoryFile) Rewind added in v1.3.2

func (f *InMemoryFile) Rewind()

Rewind resets the read pointer to 0.

func (*InMemoryFile) Seek added in v0.10.0

func (f *InMemoryFile) Seek(pos int)

Seek sets the read pointer to pos.

func (*InMemoryFile) Stat added in v0.10.0

func (f *InMemoryFile) Stat() (FileInfo, error)

func (*InMemoryFile) Write added in v0.10.0

func (f *InMemoryFile) Write(p []byte) (int, error)

Write writes the contents of p to the file from the current position. It moves the read pointer by the length of the written data. The return value n is the length of p; err is always nil.

type Mount

type Mount struct {
	Source FS
	Target string
	Type   string
}

type NilFile added in v0.10.0

type NilFile struct{}

func (*NilFile) Close added in v0.10.0

func (f *NilFile) Close() error

func (*NilFile) Read added in v0.10.0

func (f *NilFile) Read(p []byte) (n int, err error)

func (*NilFile) ReadAt added in v0.10.0

func (f *NilFile) ReadAt(p []byte, off int64) (n int, err error)

func (*NilFile) Seek added in v0.10.0

func (f *NilFile) Seek(offset int64, whence int) (int64, error)

func (*NilFile) Stat added in v0.10.0

func (f *NilFile) Stat() (FileInfo, error)

func (*NilFile) Write added in v0.10.0

func (f *NilFile) Write(p []byte) (n int, err error)

type OS

type OS interface {
	FS
	Args() []string
	Chdir(dir string) error
	Environ() []string
	Exit(code int)
	Getenv(key string) string
	Getpid() int
	Getuid() int
	Getwd() (dir string, err error)
	Hostname() (name string, err error)
	LookupEnv(key string) (string, bool)
	MkdirTemp(dir, pattern string) (string, error)
	Setenv(key, value string) error
	TempDir() string
	Unsetenv(key string) error
	UserCacheDir() (string, error)
	UserConfigDir() (string, error)
	UserHomeDir() (string, error)
	Stdin() File
	Stdout() File
	PathSeparator() rune
	PathListSeparator() rune
}

func GetDefaultOS added in v0.10.0

func GetDefaultOS(ctx context.Context) OS

GetDefaultOS returns the OS from the context, if it exists. Otherwise, it returns a new SimpleOS.

func GetOS

func GetOS(ctx context.Context) (OS, bool)

GetOS returns the OS from the context, if it exists.

type Option

type Option func(*VirtualOS)

Option is a configuration function for a Virtual Machine.

func WithArgs added in v1.1.0

func WithArgs(args []string) Option

set the args passed to the os package for os.args()

func WithCwd

func WithCwd(cwd string) Option

WithCwd sets the current working directory.

func WithEnvironment

func WithEnvironment(env map[string]string) Option

WithEnvironment sets the user home directory.

func WithExitHandler

func WithExitHandler(exitHandler ExitHandler) Option

WithExitHandler sets the exit handler.

func WithHostname

func WithHostname(hostname string) Option

WithHostname sets the hostname.

func WithMounts

func WithMounts(mounts map[string]*Mount) Option

WithMounts sets the mounts.

func WithPid

func WithPid(pid int) Option

WithPid sets the process ID.

func WithStdin added in v0.10.0

func WithStdin(stdin File) Option

WithStdin sets the stdin.

func WithStdout added in v0.10.0

func WithStdout(stdout File) Option

WithStdout sets the stdout.

func WithTmp

func WithTmp(tmp string) Option

WithTmp sets the path to the temporary directory.

func WithUid

func WithUid(uid int) Option

WithUid sets the user ID.

func WithUserCacheDir

func WithUserCacheDir(dir string) Option

WithUserCacheDir sets the user cache directory.

func WithUserConfigDir

func WithUserConfigDir(dir string) Option

WithUserConfigDir sets the user config directory.

func WithUserHomeDir

func WithUserHomeDir(dir string) Option

WithUserHomeDir sets the user home directory.

type ReadDirFile

type ReadDirFile = fs.ReadDirFile

type SimpleOS

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

func NewSimpleOS

func NewSimpleOS(ctx context.Context) *SimpleOS

func (*SimpleOS) Args added in v1.1.0

func (osObj *SimpleOS) Args() []string

func (*SimpleOS) Chdir

func (osObj *SimpleOS) Chdir(dir string) error

func (*SimpleOS) Create

func (osObj *SimpleOS) Create(name string) (File, error)

func (*SimpleOS) Environ

func (osObj *SimpleOS) Environ() []string

func (*SimpleOS) Exit

func (osObj *SimpleOS) Exit(code int)

func (*SimpleOS) Getenv

func (osObj *SimpleOS) Getenv(key string) string

func (*SimpleOS) Getpid

func (osObj *SimpleOS) Getpid() int

func (*SimpleOS) Getuid

func (osObj *SimpleOS) Getuid() int

func (*SimpleOS) Getwd

func (osObj *SimpleOS) Getwd() (string, error)

func (*SimpleOS) Hostname

func (osObj *SimpleOS) Hostname() (string, error)

func (*SimpleOS) LookupEnv

func (osObj *SimpleOS) LookupEnv(key string) (string, bool)

func (*SimpleOS) Mkdir

func (osObj *SimpleOS) Mkdir(name string, perm FileMode) error

func (*SimpleOS) MkdirAll

func (osObj *SimpleOS) MkdirAll(path string, perm FileMode) error

func (*SimpleOS) MkdirTemp

func (osObj *SimpleOS) MkdirTemp(dir, pattern string) (string, error)

func (*SimpleOS) Open

func (osObj *SimpleOS) Open(name string) (File, error)

func (*SimpleOS) OpenFile added in v1.3.0

func (osObj *SimpleOS) OpenFile(name string, flag int, perm FileMode) (File, error)

func (*SimpleOS) PathListSeparator added in v1.3.0

func (osObj *SimpleOS) PathListSeparator() rune

func (*SimpleOS) PathSeparator added in v1.3.0

func (osObj *SimpleOS) PathSeparator() rune

func (*SimpleOS) ReadDir

func (osObj *SimpleOS) ReadDir(name string) ([]DirEntry, error)

func (*SimpleOS) ReadFile

func (osObj *SimpleOS) ReadFile(name string) ([]byte, error)

func (*SimpleOS) Remove

func (osObj *SimpleOS) Remove(name string) error

func (*SimpleOS) RemoveAll added in v0.13.0

func (osObj *SimpleOS) RemoveAll(path string) error

func (*SimpleOS) Rename

func (osObj *SimpleOS) Rename(oldpath, newpath string) error

func (*SimpleOS) Setenv

func (osObj *SimpleOS) Setenv(key, value string) error

func (*SimpleOS) Stat

func (osObj *SimpleOS) Stat(name string) (os.FileInfo, error)

func (*SimpleOS) Stdin added in v0.10.0

func (osObj *SimpleOS) Stdin() File

func (*SimpleOS) Stdout added in v0.10.0

func (osObj *SimpleOS) Stdout() File
func (osObj *SimpleOS) Symlink(oldname, newname string) error

func (*SimpleOS) TempDir

func (osObj *SimpleOS) TempDir() string

func (*SimpleOS) Unsetenv

func (osObj *SimpleOS) Unsetenv(key string) error

func (*SimpleOS) UserCacheDir

func (osObj *SimpleOS) UserCacheDir() (string, error)

func (*SimpleOS) UserConfigDir

func (osObj *SimpleOS) UserConfigDir() (string, error)

func (*SimpleOS) UserHomeDir

func (osObj *SimpleOS) UserHomeDir() (string, error)

func (*SimpleOS) WalkDir added in v1.2.0

func (osObj *SimpleOS) WalkDir(root string, fn WalkDirFunc) error

func (*SimpleOS) WriteFile

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

type VirtualOS

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

func NewVirtualOS

func NewVirtualOS(ctx context.Context, opts ...Option) *VirtualOS

NewVirtualOS creates a new VirtualOS configured with the given options.

func (*VirtualOS) Args added in v1.1.0

func (osObj *VirtualOS) Args() []string

func (*VirtualOS) Chdir

func (osObj *VirtualOS) Chdir(dir string) error

func (*VirtualOS) Create

func (osObj *VirtualOS) Create(name string) (File, error)

func (*VirtualOS) Environ

func (osObj *VirtualOS) Environ() []string

func (*VirtualOS) Exit

func (osObj *VirtualOS) Exit(code int)

func (*VirtualOS) Getenv

func (osObj *VirtualOS) Getenv(key string) string

func (*VirtualOS) Getpid

func (osObj *VirtualOS) Getpid() int

func (*VirtualOS) Getuid

func (osObj *VirtualOS) Getuid() int

func (*VirtualOS) Getwd

func (osObj *VirtualOS) Getwd() (string, error)

func (*VirtualOS) Hostname

func (osObj *VirtualOS) Hostname() (string, error)

func (*VirtualOS) LookupEnv

func (osObj *VirtualOS) LookupEnv(key string) (string, bool)

func (*VirtualOS) Mkdir

func (osObj *VirtualOS) Mkdir(name string, perm FileMode) error

func (*VirtualOS) MkdirAll

func (osObj *VirtualOS) MkdirAll(path string, perm FileMode) error

func (*VirtualOS) MkdirTemp

func (osObj *VirtualOS) MkdirTemp(dir, pattern string) (string, error)

func (*VirtualOS) Open

func (osObj *VirtualOS) Open(name string) (File, error)

func (*VirtualOS) OpenFile added in v1.3.0

func (osObj *VirtualOS) OpenFile(name string, flag int, perm FileMode) (File, error)

func (*VirtualOS) PathListSeparator added in v1.3.0

func (osObj *VirtualOS) PathListSeparator() rune

func (*VirtualOS) PathSeparator added in v1.3.0

func (osObj *VirtualOS) PathSeparator() rune

func (*VirtualOS) ReadDir

func (osObj *VirtualOS) ReadDir(name string) ([]DirEntry, error)

func (*VirtualOS) ReadFile

func (osObj *VirtualOS) ReadFile(name string) ([]byte, error)

func (*VirtualOS) Remove

func (osObj *VirtualOS) Remove(name string) error

func (*VirtualOS) RemoveAll added in v0.13.0

func (osObj *VirtualOS) RemoveAll(path string) error

func (*VirtualOS) Rename

func (osObj *VirtualOS) Rename(oldpath, newpath string) error

func (*VirtualOS) SetArgs added in v1.1.0

func (osObj *VirtualOS) SetArgs(args []string)

a way to override or set the args passed to the os package would typically be used when risor is employed in an embedded manner

func (*VirtualOS) Setenv

func (osObj *VirtualOS) Setenv(key, value string) error

func (*VirtualOS) Stat

func (osObj *VirtualOS) Stat(name string) (os.FileInfo, error)

func (*VirtualOS) Stdin added in v0.10.0

func (osObj *VirtualOS) Stdin() File

func (*VirtualOS) Stdout added in v0.10.0

func (osObj *VirtualOS) Stdout() File
func (osObj *VirtualOS) Symlink(oldname, newname string) error

func (*VirtualOS) TempDir

func (osObj *VirtualOS) TempDir() string

func (*VirtualOS) Unsetenv

func (osObj *VirtualOS) Unsetenv(key string) error

func (*VirtualOS) UserCacheDir

func (osObj *VirtualOS) UserCacheDir() (string, error)

func (*VirtualOS) UserConfigDir

func (osObj *VirtualOS) UserConfigDir() (string, error)

func (*VirtualOS) UserHomeDir

func (osObj *VirtualOS) UserHomeDir() (string, error)

func (*VirtualOS) WalkDir added in v1.2.0

func (osObj *VirtualOS) WalkDir(root string, fn WalkDirFunc) error

func (*VirtualOS) WriteFile

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

type WalkDirFunc added in v1.2.0

type WalkDirFunc = fs.WalkDirFunc

Directories

Path Synopsis
s3fs module

Jump to

Keyboard shortcuts

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