package fspath
import "gvisor.dev/gvisor/pkg/fspath"
Package fspath provides efficient tools for working with file paths in Linux-compatible filesystem implementations.
Index ¶
- type Builder
- func (b *Builder) AppendString(str string)
- func (b *Builder) Len() int
- func (b *Builder) PrependByte(c byte)
- func (b *Builder) PrependComponent(pc string)
- func (b *Builder) PrependString(str string)
- func (b *Builder) Reset()
- func (b *Builder) String() string
- type Iterator
- func (it Iterator) Next() Iterator
- func (it Iterator) NextOk() bool
- func (it Iterator) Ok() bool
- func (it Iterator) String() string
- type Path
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is similar to strings.Builder, but is used to produce pathnames given path components in reverse order (from leaf to root). This is useful in the common case where a filesystem is represented by a tree of named nodes, and the path to a given node must be produced by walking upward from that node to a given root.
func (*Builder) AppendString ¶
AppendString appends the given string to b's buffer.
func (*Builder) Len ¶
Len returns the number of accumulated bytes.
func (*Builder) PrependByte ¶
PrependByte prepends the given byte to b's buffer.
func (*Builder) PrependComponent ¶
PrependComponent prepends the given path component to b's buffer. A path separator is automatically inserted if appropriate.
func (*Builder) PrependString ¶
PrependString prepends the given string to b's buffer.
func (*Builder) Reset ¶
func (b *Builder) Reset()
Reset resets the Builder to be empty.
func (*Builder) String ¶
String returns the accumulated string. No other methods should be called after String.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
An Iterator represents either a path component in a Path or a terminal iterator indicating that the end of the path has been reached.
Iterator is immutable and copyable by value. The zero value of Iterator is valid, and represents a terminal iterator.
func (Iterator) Next ¶
Next returns an iterator to the path component after it. If it is the last component in the path, Next returns a terminal iterator.
Preconditions: it.Ok().
func (Iterator) NextOk ¶
NextOk is equivalent to it.Next().Ok(), but is faster.
Preconditions: it.Ok().
func (Iterator) Ok ¶
Ok returns true if it is not terminal.
func (Iterator) String ¶
String returns the path component represented by it.
Preconditions: it.Ok().
type Path ¶
type Path struct { // Begin is an iterator to the first path component in the relative part of // the path. // // Path doesn't store information about path components after the first // since this would require allocation. Begin Iterator // If true, the path is absolute, such that lookup should begin at the // filesystem root. If false, the path is relative, such that where lookup // begins is unspecified. Absolute bool // If true, the pathname contains trailing path separators, so the last // path component must exist and resolve to a directory. Dir bool }
Path contains the information contained in a pathname string.
Path is copyable by value. The zero value for Path is equivalent to fspath.Parse(""), i.e. the empty path.
func Parse ¶
Parse parses a pathname as described by path_resolution(7), except that empty pathnames will be parsed successfully to a Path for which Path.Absolute == Path.Dir == Path.HasComponents() == false. (This is necessary to support AT_EMPTY_PATH.)
func (Path) HasComponents ¶
HasComponents returns true if p contains a non-zero number of path components.
func (Path) String ¶
String returns a pathname string equivalent to p. Note that the returned string is not necessarily equal to the string p was parsed from; in particular, redundant path separators will not be present.
Source Files ¶
builder.go fspath.go
- Version
- v0.0.0-20250605235530-a6711d1e1dc6 (latest)
- Published
- Jun 5, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 4 hours ago –
Tools for package owners.