path

package
v0.0.0-...-70e5bc8 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 5 Imported by: 30

Documentation

Overview

Package path provides tools for parsing and printing file names. File names always start with a user name in mail-address form, followed by a slash and a possibly empty path name that follows. Thus the root of user@google.com's name space is "user@google.com/". But Parse also allows "user@google.com" to refer to the user's root directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(path upspin.PathName) upspin.PathName

Clean applies Go's path.Clean to an Upspin path.

func DropPath

func DropPath(pathName upspin.PathName, n int) upspin.PathName

DropPath returns the path name with the last n elements dropped. It "cleans" the argument first, using the Clean function, which means that if the path is malformed or contains dot-dot (..) elements the result may be unexpected. The result has also been "cleaned" by the Clean function.

func FirstPath

func FirstPath(pathName upspin.PathName, n int) upspin.PathName

FirstPath returns the path name with the first n elements dropped. It "cleans" the argument first, using the Clean function, which means that if the path is malformed or contains dot-dot (..) elements the result may be unexpected. The result has also been "cleaned" by the Clean function.

func Join

func Join(path upspin.PathName, elems ...string) upspin.PathName

Join appends any number of path elements onto a (possibly empty) Upspin path, adding a separating slash if necessary. All empty strings are ignored. The result, if non-empty, is passed through Clean. There is no guarantee that the resulting path is a valid Upspin path. This differs from path.Join in that it requires a first argument of type upspin.PathName.

Types

type Parsed

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

Parsed represents a successfully parsed path name.

func Parse

func Parse(pathName upspin.PathName) (Parsed, error)

Parse parses a full file name, including the user, validates it, and returns its parsed form. If the name is a user root directory, the trailing slash is optional. The name is 'cleaned' (see the Clean function) to canonicalize it.

func (Parsed) Compare

func (p Parsed) Compare(q Parsed) int

Compare returns -1, 0, or 1 according to whether p is less than, equal to, or greater than q. The comparison is elementwise starting with the domain name, then the user name, then the path elements.

func (Parsed) Drop

func (p Parsed) Drop(n int) Parsed

Drop returns a parsed name with the last n elements dropped. See the comment on DropPath for more information.

func (Parsed) Elem

func (p Parsed) Elem(n int) string

Elem returns the nth element of the path. It panics if n is out of range.

func (Parsed) Equal

func (p Parsed) Equal(q Parsed) bool

Equal reports whether the two parsed path names are equal.

func (Parsed) FilePath

func (p Parsed) FilePath() string

FilePath returns just the path under the root directory part of the pathname, without the leading user name or slash.

func (Parsed) First

func (p Parsed) First(n int) Parsed

First returns a parsed name with only the first n elements after the user name. See the comment on FirstPath for more information.

func (Parsed) HasPrefix

func (p Parsed) HasPrefix(root Parsed) bool

HasPrefix reports whether the path has the specified element-wise prefix. That is, it reports whether name is in the subtree starting at root.

func (Parsed) IsRoot

func (p Parsed) IsRoot() bool

IsRoot reports whether a parsed name refers to the user's root.

func (*Parsed) MarshalJSON

func (p *Parsed) MarshalJSON() ([]byte, error)

MarshalJSON is needed because Parsed has unexported fields.

func (Parsed) NElem

func (p Parsed) NElem() int

NElem returns number of elements in the path.

func (Parsed) Path

func (p Parsed) Path() upspin.PathName

Path returns the string representation with type upspin.PathName.

func (Parsed) String

func (p Parsed) String() string

func (*Parsed) UnmarshalJSON

func (p *Parsed) UnmarshalJSON(data []byte) error

UnmarshalJSON is needed because Parsed has unexported fields.

func (Parsed) User

func (p Parsed) User() upspin.UserName

User returns the name of the user that owns this path.

Jump to

Keyboard shortcuts

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