Documentation
¶
Overview ¶
Package acfs provides filesystem operations for Arcane, either confined to a root directory (Root) or on absolute host paths (Host).
Root never reads, writes, or follows a link outside its Path. Some mutations resolve links inside the root in the parent path and others refuse them; the README lists which. On Linux mutations act on a parent opened by descriptor without following links; other systems check, then act by path. A write that finds its staged or published file replaced reports ErrReplaced.
Operating system errors are wrapped, so errors.Is with fs.ErrNotExist, fs.ErrExist, and os.ErrPermission keeps working. RemoveAll ignores a missing target; Remove reports it.
Writes are atomic by default and stage a temporary file with the reserved ".acfs-write-" prefix, which paths may not use and listings hide.
Index ¶
- Constants
- Variables
- func ReadStreamHeader(source io.Reader) (uint64, error)
- func WriteStreamHeader(destination io.Writer, payloadLength uint64) error
- type FS
- type Host
- func (h Host) Chmod(ctx context.Context, hostPath string, mode os.FileMode) error
- func (h Host) Chown(ctx context.Context, hostPath string, uid, gid int) error
- func (h Host) Chtimes(ctx context.Context, hostPath string, atime, mtime time.Time) error
- func (Host) CopyDir(ctx context.Context, sourceDir, destinationDir string, ...) (acfstypes.CopyResult, error)
- func (Host) CreateTemp(ctx context.Context, hostDir, pattern string) (*os.File, string, error)
- func (h Host) Exists(ctx context.Context, hostPath string) (bool, error)
- func (h Host) Lchown(ctx context.Context, hostPath string, uid, gid int) error
- func (h Host) List(ctx context.Context, hostPath string) ([]acfstypes.Entry, error)
- func (Host) ListEach(ctx context.Context, hostPath string, options acfstypes.ListOptions, ...) (acfstypes.ListResult, error)
- func (Host) MirrorDir(ctx context.Context, sourceDir, destinationDir string, ...) error
- func (Host) Mkdir(ctx context.Context, hostPath string, mode os.FileMode) error
- func (Host) MkdirAll(ctx context.Context, hostPath string, mode os.FileMode) error
- func (Host) MkdirTemp(ctx context.Context, hostDir, pattern string) (string, error)
- func (h Host) OpenFile(ctx context.Context, hostPath string, options OpenOptions) (*os.File, error)
- func (h Host) OpenRead(ctx context.Context, hostPath string, maxBytes int64) (io.ReadCloser, int64, error)
- func (Host) OpenReadSeek(ctx context.Context, hostPath string) (io.ReadSeekCloser, int64, error)
- func (h Host) ReadFile(ctx context.Context, hostPath string) ([]byte, error)
- func (h Host) ReadTo(ctx context.Context, hostPath string, destination io.Writer, maxBytes int64) (int64, error)
- func (Host) Readlink(ctx context.Context, hostPath string) (string, error)
- func (Host) Remove(ctx context.Context, hostPath string) error
- func (Host) RemoveAll(ctx context.Context, hostPath string) error
- func (Host) Rename(ctx context.Context, source, target string) error
- func (Host) Stat(ctx context.Context, hostPath string, options acfstypes.StatOptions) (acfstypes.Entry, error)
- func (Host) Symlink(ctx context.Context, target, linkPath string) error
- func (Host) Sync(ctx context.Context, hostPath string) error
- func (Host) Write(ctx context.Context, hostPath string, data []byte, options WriteOptions) error
- func (Host) WriteAt(ctx context.Context, hostPath string, offset int64, data []byte) error
- func (Host) WriteFrom(ctx context.Context, hostPath string, source io.Reader, ...) (int64, error)
- type OpenOptions
- type Root
- func (r Root) Apply(ctx context.Context, staging Root, manifest acfstypes.ApplyManifest) (int, error)
- func (r Root) Chmod(ctx context.Context, logicalPath string, mode os.FileMode) error
- func (r Root) Chown(ctx context.Context, logicalPath string, uid, gid int) error
- func (r Root) Chtimes(ctx context.Context, logicalPath string, atime, mtime time.Time) error
- func (r Root) CopyTo(ctx context.Context, destination Root, options acfstypes.CopyOptions) (acfstypes.CopyResult, error)
- func (r Root) CreateTemp(ctx context.Context, logicalDir, pattern string) (*os.File, string, error)
- func (r Root) Exists(ctx context.Context, logicalPath string) (bool, error)
- func (r Root) Lchown(ctx context.Context, logicalPath string, uid, gid int) error
- func (r Root) List(ctx context.Context, logicalPath string) ([]acfstypes.Entry, error)
- func (r Root) ListEach(ctx context.Context, logicalPath string, options acfstypes.ListOptions, ...) (acfstypes.ListResult, error)
- func (r Root) LogicalPath(absPath string) (string, error)
- func (r Root) MirrorTo(ctx context.Context, destination Root, options acfstypes.MirrorOptions) error
- func (r Root) Mkdir(ctx context.Context, logicalPath string, mode os.FileMode) error
- func (r Root) MkdirAll(ctx context.Context, logicalPath string, mode os.FileMode) error
- func (r Root) MkdirTemp(ctx context.Context, logicalDir, pattern string) (string, error)
- func (r Root) OpenFile(ctx context.Context, logicalPath string, options OpenOptions) (*os.File, error)
- func (r Root) OpenRead(ctx context.Context, logicalPath string, maxBytes int64) (io.ReadCloser, int64, error)
- func (r Root) OpenReadSeek(ctx context.Context, logicalPath string) (io.ReadSeekCloser, int64, error)
- func (r Root) ReadFile(ctx context.Context, logicalPath string) ([]byte, error)
- func (r Root) ReadTo(ctx context.Context, logicalPath string, destination io.Writer, maxBytes int64) (int64, error)
- func (r Root) Readlink(ctx context.Context, logicalPath string) (string, error)
- func (r Root) Remove(ctx context.Context, logicalPath string) error
- func (r Root) RemoveAll(ctx context.Context, logicalPath string) error
- func (r Root) Rename(ctx context.Context, sourceLogical, targetLogical string) error
- func (r Root) Stat(ctx context.Context, logicalPath string, options acfstypes.StatOptions) (acfstypes.Entry, error)
- func (r Root) Symlink(ctx context.Context, target, linkPath string) (retErr error)
- func (r Root) Sync(ctx context.Context, logicalPath string) error
- func (r Root) Walk(ctx context.Context, logicalPath string, options acfstypes.WalkOptions, ...) (acfstypes.WalkResult, error)
- func (r Root) Write(ctx context.Context, logicalPath string, data []byte, options WriteOptions) error
- func (r Root) WriteAt(ctx context.Context, logicalPath string, offset int64, data []byte) error
- func (r Root) WriteFrom(ctx context.Context, logicalPath string, source io.Reader, ...) (int64, error)
- type WriteFromOptions
- type WriteOptions
Constants ¶
const (
// StreamHeaderSize is the number of bytes in an acfs read header.
StreamHeaderSize = 16
)
Variables ¶
var ( // ErrInvalidPath indicates that a logical workspace path is malformed. ErrInvalidPath = kitfs.ErrInvalidPath // ErrOutsideRoot indicates that a path or symlink escapes the workspace root. ErrOutsideRoot = errors.New("path escapes workspace root") // ErrSymlinkLoop indicates that symlink resolution exceeded its safe limit. ErrSymlinkLoop = errors.New("too many symbolic links") // ErrIsDirectory indicates that a file operation targeted a directory. ErrIsDirectory = errors.New("path is a directory") // ErrSizeMismatch indicates that a write did not contain its declared size. ErrSizeMismatch = errors.New("input size does not match declared size") // ErrRootRemoval indicates an attempt to remove the workspace root. ErrRootRemoval = errors.New("cannot remove workspace root") // ErrSymlink indicates that a mutation path contains a symbolic link. ErrSymlink = errors.New("symbolic links are not allowed for mutations") // ErrAlreadyExists indicates that a create or move destination exists. ErrAlreadyExists = errors.New("destination already exists") // ErrNotDirectory indicates that a required directory is not a directory. ErrNotDirectory = errors.New("path is not a directory") // ErrNotFile indicates that a required regular file is not a regular file. ErrNotFile = errors.New("path is not a regular file") // ErrNotEmpty indicates that a non-recursive directory removal was requested. ErrNotEmpty = errors.New("directory is not empty") // ErrInvalidOpenOptions indicates an OpenOptions combination that cannot open a file. ErrInvalidOpenOptions = errors.New("invalid open options") // ErrInvalidWriteOptions indicates a WriteOptions combination that cannot write a file. ErrInvalidWriteOptions = errors.New("invalid write options") // ErrReplaced indicates that another process replaced the staged or published // file, so the write did not succeed. ErrReplaced = errors.New("staged file was replaced during the write") )
Functions ¶
func ReadStreamHeader ¶
ReadStreamHeader validates an acfs stream header and returns its payload length.
Types ¶
type FS ¶ added in v0.8.0
type FS interface {
List(ctx context.Context, path string) ([]acfstypes.Entry, error)
ListEach(ctx context.Context, path string, options acfstypes.ListOptions, visit func(acfstypes.Entry) error) (acfstypes.ListResult, error)
Stat(ctx context.Context, path string, options acfstypes.StatOptions) (acfstypes.Entry, error)
Exists(ctx context.Context, path string) (bool, error)
OpenRead(ctx context.Context, path string, maxBytes int64) (io.ReadCloser, int64, error)
OpenReadSeek(ctx context.Context, path string) (io.ReadSeekCloser, int64, error)
ReadFile(ctx context.Context, path string) ([]byte, error)
ReadTo(ctx context.Context, path string, destination io.Writer, maxBytes int64) (int64, error)
OpenFile(ctx context.Context, path string, options OpenOptions) (*os.File, error)
CreateTemp(ctx context.Context, dir, pattern string) (*os.File, string, error)
Write(ctx context.Context, path string, data []byte, options WriteOptions) error
WriteFrom(ctx context.Context, path string, source io.Reader, options WriteFromOptions) (int64, error)
WriteAt(ctx context.Context, path string, offset int64, data []byte) error
Sync(ctx context.Context, path string) error
Mkdir(ctx context.Context, path string, mode os.FileMode) error
MkdirAll(ctx context.Context, path string, mode os.FileMode) error
MkdirTemp(ctx context.Context, dir, pattern string) (string, error)
Rename(ctx context.Context, source, target string) error
Remove(ctx context.Context, path string) error
RemoveAll(ctx context.Context, path string) error
Chmod(ctx context.Context, path string, mode os.FileMode) error
Chown(ctx context.Context, path string, uid, gid int) error
Lchown(ctx context.Context, path string, uid, gid int) error
Chtimes(ctx context.Context, path string, atime, mtime time.Time) error
Symlink(ctx context.Context, target, linkPath string) error
Readlink(ctx context.Context, path string) (string, error)
}
FS is the operation set shared by Root and Host. Copy, mirror, and Apply are Root-only; Host has CopyDir and MirrorDir.
type Host ¶ added in v0.8.0
type Host struct {
// Special lets OpenRead, ReadFile, ReadTo, and OpenFile open FIFOs and
// character devices such as /dev/stdin, blocking like the os package.
// Directories are still refused, and OpenReadSeek requires a regular file.
Special bool
}
Host offers the Root operations on absolute host paths without confinement, following symbolic links like the os package. Use acfs.Host{}.
func (Host) Chmod ¶ added in v0.8.0
Chmod changes the mode of a host path, following symbolic links.
func (Host) Chown ¶ added in v0.8.0
Chown changes the owner of a host path, following symbolic links.
func (Host) Chtimes ¶ added in v0.8.0
Chtimes changes the times of a host path, following symbolic links.
func (Host) CopyDir ¶ added in v0.8.0
func (Host) CopyDir(ctx context.Context, sourceDir, destinationDir string, options acfstypes.CopyOptions) (acfstypes.CopyResult, error)
CopyDir copies the host directory sourceDir into destinationDir like Root.CopyTo.
func (Host) CreateTemp ¶ added in v0.8.0
CreateTemp creates a uniquely named file in a host directory like Root.CreateTemp.
func (Host) Exists ¶ added in v0.8.0
Exists reports whether a host path exists. A missing target is not an error.
func (Host) Lchown ¶ added in v0.8.0
Lchown changes the owner of a host path without following its final link.
func (Host) ListEach ¶ added in v0.8.0
func (Host) ListEach(ctx context.Context, hostPath string, options acfstypes.ListOptions, visit func(acfstypes.Entry) error) (acfstypes.ListResult, error)
ListEach visits the children of a host directory in name order, bounded by options like Root.ListEach.
func (Host) MirrorDir ¶ added in v0.8.0
func (Host) MirrorDir(ctx context.Context, sourceDir, destinationDir string, options acfstypes.MirrorOptions) error
MirrorDir makes the host directory destinationDir match sourceDir like Root.MirrorTo.
func (Host) Mkdir ¶ added in v0.8.0
Mkdir creates a host directory. An existing target reports ErrAlreadyExists.
func (Host) MkdirTemp ¶ added in v0.8.0
MkdirTemp creates a uniquely named directory in a host directory like Root.MkdirTemp.
func (Host) OpenFile ¶ added in v0.8.0
OpenFile opens a host regular file, or a special file with h.Special, following symbolic links.
func (Host) OpenRead ¶ added in v0.8.0
func (h Host) OpenRead(ctx context.Context, hostPath string, maxBytes int64) (io.ReadCloser, int64, error)
OpenRead opens a host file for a streaming read of at most maxBytes when positive. A special file has no known size: it reports -1 and is read to EOF or maxBytes.
func (Host) OpenReadSeek ¶ added in v0.8.0
OpenReadSeek opens a host regular file for a seekable read.
func (Host) ReadFile ¶ added in v0.8.0
ReadFile reads a host file to EOF, so /proc files with size zero and special files are read.
func (Host) ReadTo ¶ added in v0.8.0
func (h Host) ReadTo(ctx context.Context, hostPath string, destination io.Writer, maxBytes int64) (int64, error)
ReadTo streams a host file into destination, at most maxBytes when positive.
func (Host) Remove ¶ added in v0.8.0
Remove removes a host file, symbolic link, or empty directory like Root.Remove.
func (Host) RemoveAll ¶ added in v0.8.0
RemoveAll removes a host path and its children. A missing target is not an error.
func (Host) Stat ¶ added in v0.8.0
func (Host) Stat(ctx context.Context, hostPath string, options acfstypes.StatOptions) (acfstypes.Entry, error)
Stat returns metadata for a host path, following symbolic links only with options.FollowFinal.
func (Host) Symlink ¶ added in v0.8.0
Symlink creates a host symbolic link storing target verbatim. An existing linkPath reports ErrAlreadyExists.
func (Host) Sync ¶ added in v0.10.0
Sync flushes a host regular file or directory to stable storage, following symbolic links.
type OpenOptions ¶ added in v0.8.0
type OpenOptions struct {
// Mode is the permission set of a file created by Create.
Mode os.FileMode
Read bool
Write bool
Create bool
// Exclusive, which requires Create, reports ErrAlreadyExists for an existing file.
Exclusive bool
// Truncate, which requires Write, empties an existing file.
Truncate bool
// Append, which requires Write, makes every write append to the file.
Append bool
}
OpenOptions selects how OpenFile opens a regular file. Read or Write is required.
type Root ¶
type Root struct {
// Path is the host directory that logical paths are resolved against.
Path string
}
Root confines every operation to Path. Its methods take absolute logical paths such as "/a/b"; the zero Root fails every operation.
func (Root) Apply ¶
func (r Root) Apply(ctx context.Context, staging Root, manifest acfstypes.ApplyManifest) (int, error)
Apply performs an ordered batch of root-confined mutations, stopping at the first failure.
func (Root) Chmod ¶ added in v0.8.0
Chmod changes the mode of a root-confined path, refusing symbolic links with ErrSymlink.
func (Root) Chown ¶ added in v0.8.0
Chown changes the owner of a root-confined path like Chmod. A uid or gid of -1 is unchanged.
func (Root) Chtimes ¶ added in v0.8.0
Chtimes changes the times of a root-confined path like Chmod. A zero time is unchanged.
func (Root) CopyTo ¶
func (r Root) CopyTo(ctx context.Context, destination Root, options acfstypes.CopyOptions) (acfstypes.CopyResult, error)
CopyTo copies r into destination, which may not nest with r. Links are skipped and sockets, FIFOs, and devices are recorded in CopyResult.Skipped.
func (Root) CreateTemp ¶ added in v0.8.0
CreateTemp creates a uniquely named 0o600 file in a root-confined directory and returns it open with its logical path.
func (Root) Exists ¶
Exists reports whether a root-confined path exists; a dangling final link counts. A missing target is not an error.
func (Root) Lchown ¶ added in v0.8.0
Lchown changes the owner of a root-confined path without following its final link.
func (Root) ListEach ¶
func (r Root) ListEach(ctx context.Context, logicalPath string, options acfstypes.ListOptions, visit func(acfstypes.Entry) error) (acfstypes.ListResult, error)
ListEach visits the children of a root-confined directory in name order. With options.MaxEntries, it visits only the first MaxEntries names and holds no more than twice that many in memory.
func (Root) LogicalPath ¶
LogicalPath lexically translates an absolute host path under r.Path into a logical path, reporting ErrOutsideRoot for one outside it.
func (Root) MirrorTo ¶
func (r Root) MirrorTo(ctx context.Context, destination Root, options acfstypes.MirrorOptions) error
MirrorTo makes destination match r in place, keeping inodes of bind-mounted files and tolerating unreadable or unwritable entries (#3509, #3625).
func (Root) Mkdir ¶
Mkdir creates a root-confined directory whose parent exists. An existing target reports ErrAlreadyExists, which also matches fs.ErrExist.
func (Root) MkdirTemp ¶
MkdirTemp creates a uniquely named 0o700 directory in a root-confined directory and returns its logical path. The pattern follows os.MkdirTemp.
func (Root) OpenFile ¶ added in v0.8.0
func (r Root) OpenFile(ctx context.Context, logicalPath string, options OpenOptions) (*os.File, error)
OpenFile opens a root-confined regular file. Writes and creates refuse symbolic links with ErrSymlink; read-only opens follow links inside the root.
func (Root) OpenRead ¶
func (r Root) OpenRead(ctx context.Context, logicalPath string, maxBytes int64) (io.ReadCloser, int64, error)
OpenRead opens a root-confined file for a streaming read of at most maxBytes when positive.
func (Root) OpenReadSeek ¶
func (r Root) OpenReadSeek(ctx context.Context, logicalPath string) (io.ReadSeekCloser, int64, error)
OpenReadSeek opens a root-confined regular file for a seekable read.
func (Root) ReadTo ¶
func (r Root) ReadTo(ctx context.Context, logicalPath string, destination io.Writer, maxBytes int64) (int64, error)
ReadTo streams a root-confined file into destination, at most maxBytes when positive.
func (Root) Readlink ¶ added in v0.8.0
Readlink returns the stored target of a root-confined symbolic link verbatim.
func (Root) Remove ¶
Remove removes a root-confined file, symbolic link, or empty directory. A non-empty directory reports ErrNotEmpty and a missing target is an error.
func (Root) RemoveAll ¶
RemoveAll removes a root-confined path and its children. A missing target is not an error.
func (Root) Rename ¶
Rename moves sourceLogical onto targetLogical inside the root like os.Rename, without following either final component. A cross-device rename reports EXDEV.
func (Root) Stat ¶
func (r Root) Stat(ctx context.Context, logicalPath string, options acfstypes.StatOptions) (acfstypes.Entry, error)
Stat returns metadata for a root-confined path, following the final symbolic link only with options.FollowFinal.
func (Root) Symlink ¶ added in v0.8.0
Symlink creates a root-confined symbolic link whose target must stay inside the root, storing an absolute target as the equivalent relative path.
func (Root) Sync ¶ added in v0.10.0
Sync flushes a root-confined regular file or directory to stable storage. Links in the parent path are resolved; a final link is refused with ErrSymlink.
func (Root) Walk ¶
func (r Root) Walk(ctx context.Context, logicalPath string, options acfstypes.WalkOptions, visit func(acfstypes.Entry) error) (acfstypes.WalkResult, error)
Walk visits every descendant of a root-confined directory depth-first in name order without following symbolic links.
func (Root) Write ¶
func (r Root) Write(ctx context.Context, logicalPath string, data []byte, options WriteOptions) error
Write atomically replaces a root-confined file with data, or rewrites it in place with options.InPlace.
type WriteFromOptions ¶
type WriteFromOptions struct {
// Size is the exact number of bytes to read from the source.
Size int64
// Mode is the permission set of the written file.
Mode os.FileMode
// Exclusive publishes the file only if the target does not exist, reporting
// ErrAlreadyExists otherwise.
Exclusive bool
}
WriteFromOptions configures WriteFrom.
type WriteOptions ¶
type WriteOptions struct {
Mode os.FileMode
// InPlace keeps existing inodes and refuses a final symbolic link, but is not atomic.
InPlace bool
// Exclusive publishes the file only if the target does not exist, reporting
// ErrAlreadyExists otherwise. It cannot be combined with InPlace.
Exclusive bool
}
WriteOptions configures a write.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
cli
Package cli implements the acfs command-line protocol.
|
Package cli implements the acfs command-line protocol. |
|
version
Package version contains build metadata injected by GoReleaser.
|
Package version contains build metadata injected by GoReleaser. |
|
Package types contains the public data contracts used by ACFS and its command-line protocol.
|
Package types contains the public data contracts used by ACFS and its command-line protocol. |