Documentation
¶
Overview ¶
Package memory is an in-memory harness.FileSystem port: POSIX virtual paths, files and directories, no symlinks. It never touches a host filesystem and holds no package-level state.
Index ¶
- Variables
- type FileSystem
- func (fsys *FileSystem) AbsolutePath(_ context.Context, name string) (string, error)
- func (fsys *FileSystem) AppendFile(ctx context.Context, name string, content []byte) error
- func (fsys *FileSystem) CanonicalPath(ctx context.Context, name string) (string, error)
- func (fsys *FileSystem) Cleanup() error
- func (fsys *FileSystem) CreateDir(ctx context.Context, name string, recursive bool) error
- func (fsys *FileSystem) CreateTempDir(ctx context.Context, prefix string) (string, error)
- func (fsys *FileSystem) CreateTempFile(ctx context.Context, prefix, suffix string) (string, error)
- func (fsys *FileSystem) Exists(ctx context.Context, name string) (bool, error)
- func (fsys *FileSystem) FileInfo(ctx context.Context, name string) (harness.FileInfo, error)
- func (fsys *FileSystem) JoinPath(_ context.Context, parts ...string) (string, error)
- func (fsys *FileSystem) ListDir(ctx context.Context, name string) ([]harness.FileInfo, error)
- func (fsys *FileSystem) ReadBinaryFile(ctx context.Context, name string) ([]byte, error)
- func (fsys *FileSystem) ReadTextFile(ctx context.Context, name string) (string, error)
- func (fsys *FileSystem) ReadTextLines(ctx context.Context, name string, maxLines int) ([]string, error)
- func (fsys *FileSystem) Remove(ctx context.Context, name string, recursive, force bool) error
- func (fsys *FileSystem) RenameFile(ctx context.Context, from, to string) error
- func (fsys *FileSystem) Snapshot() map[string]string
- func (fsys *FileSystem) WorkingDirectory() string
- func (fsys *FileSystem) WriteFile(ctx context.Context, name string, content []byte) error
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrLimitExceeded = errors.New("memory file system limit exceeded")
ErrLimitExceeded is wrapped by the FileError returned when a write would exceed Options.MaxBytes or Options.MaxFiles.
Functions ¶
This section is empty.
Types ¶
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem is safe for concurrent use.
func New ¶
func New(options Options) *FileSystem
func (*FileSystem) AbsolutePath ¶
func (*FileSystem) AppendFile ¶
func (*FileSystem) CanonicalPath ¶
func (*FileSystem) Cleanup ¶
func (fsys *FileSystem) Cleanup() error
func (*FileSystem) CreateDir ¶
CreateDir matches NodeExecutionEnv (Go's MkdirAll): a recursive create over an existing file reports not_directory; a non-recursive create over any existing entry reports unknown (EEXIST).
func (*FileSystem) CreateTempDir ¶
CreateTempDir creates directories under <Root>/tmp.
func (*FileSystem) CreateTempFile ¶
func (*FileSystem) ReadBinaryFile ¶
func (*FileSystem) ReadTextFile ¶
func (*FileSystem) ReadTextLines ¶
func (fsys *FileSystem) ReadTextLines(ctx context.Context, name string, maxLines int) ([]string, error)
ReadTextLines matches NodeExecutionEnv: maxLines <= 0 reads nothing and does not open the file.
func (*FileSystem) Remove ¶
Remove matches NodeExecutionEnv: a non-recursive remove of any directory fails with unknown (Node's ERR_FS_EISDIR) and force ignores only missing paths. The root cannot be removed.
func (*FileSystem) RenameFile ¶
func (fsys *FileSystem) RenameFile(ctx context.Context, from, to string) error
RenameFile follows rename(2): a file replaces a file, a directory replaces a missing or empty directory. Errors carry the source path like Node's.
func (*FileSystem) Snapshot ¶
func (fsys *FileSystem) Snapshot() map[string]string
Snapshot returns a copy of every regular file's content keyed by path.
func (*FileSystem) WorkingDirectory ¶
func (fsys *FileSystem) WorkingDirectory() string
type Options ¶
type Options struct {
// Root is the working directory and the confinement boundary: paths
// resolving outside it fail with permission_denied. Defaults to "/".
Root string
// MaxBytes bounds the total size of file contents; zero is unbounded.
MaxBytes int64
// MaxFiles bounds the number of regular files; zero is unbounded.
MaxFiles int
// Now stamps modification times; defaults to time.Now.
Now func() time.Time
}