Documentation
¶
Index ¶
- Variables
- func CloseRoot(file *os.File)
- func HasTrailingDirSyntax(relPath string) bool
- func OpenFile(rootFile *os.File, _ *os.Root, relPath string, flag int, perm os.FileMode) (*os.File, error)
- func OpenRoot(root *os.Root) (*os.File, error)
- func Unlink(rootFile *os.File, _ *os.Root, relPath string) error
Constants ¶
This section is empty.
Variables ¶
var ErrIsDirectory = errors.New("is a directory")
ErrIsDirectory reports that Unlink's target is a directory.
var ErrNotDirectory = errors.New("not a directory")
ErrNotDirectory reports that a path passed to Unlink syntactically required its target to be a directory (a trailing separator, or a final "." or ".." component) but the resolved target is not one.
var ErrNotRegularFile = errors.New("not a regular file")
ErrNotRegularFile reports that a write target is not a regular file.
It is returned both by the post-open fstat guard and by the open itself when the kernel refuses the open with ENXIO. ENXIO is not exclusively "FIFO opened O_WRONLY|O_NONBLOCK with no reader attached" — some device nodes report it too — but every ENXIO case here describes a non-regular target, which is the only thing rshell's write paths accept. Normalizing it keeps the message identical regardless of whether a reader happened to be attached at open time, and avoids leaking the raw platform errno text ("device not configured" on macOS, "no such device or address" on Linux).
var ErrSymlinkWriteTarget = errors.New("symlinks are not supported as write targets")
ErrSymlinkWriteTarget reports a symlink in a write target. Writes reject symlinks rather than following them so the target cannot change between resolution and open.
Functions ¶
func HasTrailingDirSyntax ¶ added in v0.0.24
HasTrailingDirSyntax reports whether relPath, as literally passed to Unlink, syntactically requires its target to resolve as a directory: it ends in a path separator, or its final component is "." or "..". POSIX/GNU tools reject such operands (e.g. "file/", "file/.") with ENOTDIR when the target — after following any symlink, since a trailing separator forces dereference — is not a directory, rather than silently operating on whatever remains once path cleaning drops the trailing syntax. "/" is always checked since it is the shell's own path-separator syntax; "\" is only a separator on Windows — on Unix it is a valid filename character.
Exported so Sandbox.Remove can detect this syntax on the caller's raw path before toAbs's filepath.Join cleans the trailing separator away, and re-encode the requirement onto relPath before calling Unlink.
func Unlink ¶ added in v0.0.24
Unlink removes relPath via an atomic, no-follow openat walk to the parent directory followed by unlinkat on the held directory fd. Intermediate components are rejected if they are symlinks (same as OpenFile); the final component may be a symlink, since unlink(2) removes the link itself without following it — unless relPath itself syntactically demands directory semantics (a trailing separator, or a final "." / ".." component, e.g. "file/" or "symlink-to-file/"), in which case POSIX forces the target to be dereferenced before the directory check. Directories are rejected via fstatat on the same held fd, closing the TOCTOU window between a directory check and the actual removal.
Types ¶
This section is empty.