Documentation ¶
Overview ¶
Package relpath implements a recursive relative path tree.
Index ¶
- func SetGlobalParent(p *RelPath)
- type RelPath
- func (p *RelPath) Abs() (string, error)
- func (p *RelPath) Add(p2 *RelPath) (ret *RelPath)
- func (p *RelPath) Append(path string)
- func (p *RelPath) Base() string
- func (p *RelPath) Chdir() error
- func (p *RelPath) Chmod(mode os.FileMode) error
- func (p *RelPath) Chown(uid, gid int) error
- func (p *RelPath) Chtimes(atime, mtime time.Time) error
- func (p *RelPath) Clean() string
- func (p *RelPath) Copy() *RelPath
- func (p *RelPath) CopyDetached() *RelPath
- func (p *RelPath) Dir() string
- func (p *RelPath) DirFS() fs.FS
- func (p *RelPath) Equal(p2 *RelPath) bool
- func (p *RelPath) EqualAbsLexical(p2 *RelPath) bool
- func (p *RelPath) EqualLexical(p2 *RelPath) bool
- func (p *RelPath) EqualObject(p2 *RelPath) bool
- func (p *RelPath) EqualTree(p2 *RelPath) bool
- func (p *RelPath) EvalSymlinks() (string, error)
- func (p *RelPath) Exists() bool
- func (p *RelPath) Ext() string
- func (p *RelPath) FromSlash() string
- func (p *RelPath) IsAbs() bool
- func (p *RelPath) Lchown(uid, gid int) error
- func (p *RelPath) Link(newname string) error
- func (p *RelPath) Lstat() (os.FileInfo, error)
- func (p *RelPath) MarshalJSON() ([]byte, error)
- func (p *RelPath) Mkdir(name string, perm os.FileMode) error
- func (p *RelPath) MkdirAll(name string, perm os.FileMode) error
- func (p *RelPath) Open() (*os.File, error)
- func (p *RelPath) OpenFile(flag int, perm os.FileMode) (*os.File, error)
- func (p *RelPath) Path() string
- func (p *RelPath) Prepend(path string)
- func (p *RelPath) ReadDir() ([]os.DirEntry, error)
- func (p *RelPath) ReadFile() ([]byte, error)
- func (p *RelPath) Readlink() (string, error)
- func (p *RelPath) RelPath() string
- func (p *RelPath) Relative(path string) *RelPath
- func (p *RelPath) Remove() error
- func (p *RelPath) RemoveAll() error
- func (p *RelPath) Rename(newpath string) error
- func (p *RelPath) Resolve() (path string, err error)
- func (p *RelPath) Split() (string, string)
- func (p *RelPath) SplitList() []string
- func (p *RelPath) Stat() (os.FileInfo, error)
- func (p *RelPath) String() string
- func (p *RelPath) Symlink(newname string) error
- func (p *RelPath) ToAbsolute() error
- func (p *RelPath) ToSlash() string
- func (p *RelPath) Touch() (err error)
- func (p *RelPath) UnmarshalJSON(data []byte) error
- func (p *RelPath) VolumeName() string
- func (p *RelPath) Walk(fn filepath.WalkFunc) error
- func (p *RelPath) WalkDir(fn fs.WalkDirFunc) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetGlobalParent ¶
func SetGlobalParent(p *RelPath)
SetGlobalParent sets a global prefix to all the RelPath objects created afterwards.
Types ¶
type RelPath ¶
type RelPath struct {
// contains filtered or unexported fields
}
func (*RelPath) Abs ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func (*RelPath) Base ¶
Base returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator.
func (*RelPath) Chdir ¶
Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.
func (*RelPath) Chmod ¶
Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError.
A different subset of the mode bits are used, depending on the operating system.
On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used.
On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file.
On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used.
func (*RelPath) Chown ¶
Chown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link's target. A uid or gid of -1 means to not change that value. If there is an error, it will be of type *PathError.
On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or EPLAN9 error, wrapped in *PathError.
func (*RelPath) Chtimes ¶
Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions.
The underlying filesystem may truncate or round the values to a less precise time unit. If there is an error, it will be of type *PathError.
func (*RelPath) Clean ¶
Clean returns the shortest path name equivalent to path by purely lexical processing.
func (*RelPath) CopyDetached ¶
CopyDetached copies the current RelPath while detaching it from its tree, creating a standalone new RelPath object.
func (*RelPath) Dir ¶
Dir returns all but the last element of path, typically the path's directory. After dropping the final element, Dir calls Clean on the path and trailing slashes are removed. If the path is empty, Dir returns ".". If the path consists entirely of separators, Dir returns a single separator. The returned path does not end in a separator unless it is the root directory.
func (*RelPath) DirFS ¶
DirFS returns a file system (an fs.FS) for the tree of files rooted at the directory dir.
Note that DirFS("/prefix") only guarantees that the Open calls it makes to the operating system will begin with "/prefix": DirFS("/prefix").Open("file") is the same as os.Open("/prefix/file"). So if /prefix/file is a symbolic link pointing outside the /prefix tree, then using DirFS does not stop the access any more than using os.Open does. DirFS is therefore not a general substitute for a chroot-style security mechanism when the directory tree contains arbitrary content.
func (*RelPath) Equal ¶
Equal compares if the 2 files are actually the same file. If any one of them does not exist, it returns false.
func (*RelPath) EqualAbsLexical ¶
EqualAbsLexical compares if the 2 RelPath objects have the same path when converted to absolute paths.
func (*RelPath) EqualLexical ¶
EqualLexical compares if the 2 RelPath objects have the same path.
func (*RelPath) EqualObject ¶
EqualObject compares if the 2 RelPath objects have the same internal data fields.
func (*RelPath) EvalSymlinks ¶
EvalSymlinks returns the path name after the evaluation of any symbolic links. If path is relative the result will be relative to the current directory, unless one of the components is an absolute symbolic link. EvalSymlinks calls Clean on the result.
func (*RelPath) Ext ¶
Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.
func (*RelPath) FromSlash ¶
FromSlash returns the result of replacing each slash ('/') character in path with a separator character. Multiple slashes are replaced by multiple separators.
func (*RelPath) Lchown ¶
Lchown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link itself. If there is an error, it will be of type *PathError.
On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError.
func (*RelPath) Link ¶
Link creates newname as a hard link to the oldname file. If there is an error, it will be of type *LinkError.
func (*RelPath) Lstat ¶
Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.
func (*RelPath) MarshalJSON ¶
func (*RelPath) Mkdir ¶
Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type *PathError.
func (*RelPath) MkdirAll ¶
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
func (*RelPath) Open ¶
Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.
func (*RelPath) Prepend ¶
Prepend prepends a path segment before the top of the RelPath tree. It affects all RelPath objects inherited from this tree.
func (*RelPath) ReadDir ¶
ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error.
func (*RelPath) ReadFile ¶
ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
func (*RelPath) Readlink ¶
Readlink returns the destination of the named symbolic link. If there is an error, it will be of type *PathError.
func (*RelPath) Relative ¶
Relative creates a RelPath object that is relative to the current RelPath.
func (*RelPath) Remove ¶
Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.
func (*RelPath) RemoveAll ¶
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *PathError.
func (*RelPath) Rename ¶
Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *LinkError.
Note: Rename will detach the RelPath object from its inheritance tree.
func (*RelPath) Resolve ¶
Resolve returns the absolute path of the actual file (with symlinks resolved).
func (*RelPath) Split ¶
Split splits path immediately following the final Separator, separating it into a directory and file name component. If there is no Separator in path, Split returns an empty dir and file set to path. The returned values have the property that path = dir+file.
func (*RelPath) SplitList ¶
SplitList splits a list of paths joined by the OS-specific ListSeparator, usually found in PATH or GOPATH environment variables. Unlike strings.Split, SplitList returns an empty slice when passed an empty string.
func (*RelPath) Stat ¶
Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.
func (*RelPath) Symlink ¶
Symlink creates newname as a symbolic link to oldname. On Windows, a symlink to a non-existent oldname creates a file symlink; if oldname is later created as a directory the symlink will not work. If there is an error, it will be of type *LinkError.
func (*RelPath) ToAbsolute ¶
func (*RelPath) ToSlash ¶
ToSlash returns the result of replacing each separator character in path with a slash ('/') character. Multiple separators are replaced by multiple slashes.
func (*RelPath) UnmarshalJSON ¶
func (*RelPath) VolumeName ¶
VolumeName returns leading volume name. Given "C:\foo\bar" it returns "C:" on Windows. Given "\\host\share\foo" it returns "\\host\share". On other platforms it returns "".
func (*RelPath) Walk ¶
Walk walks the file tree rooted at root, calling fn for each file or directory in the tree, including root.
All errors that arise visiting files and directories are filtered by fn: see the WalkFunc documentation for details.
The files are walked in lexical order, which makes the output deterministic but requires Walk to read an entire directory into memory before proceeding to walk that directory.
Walk does not follow symbolic links.
Walk is less efficient than WalkDir, introduced in Go 1.16, which avoids calling os.Lstat on every visited file or directory.
func (*RelPath) WalkDir ¶
func (p *RelPath) WalkDir(fn fs.WalkDirFunc) error
WalkDir walks the file tree rooted at root, calling fn for each file or directory in the tree, including root.
All errors that arise visiting files and directories are filtered by fn: see the fs.WalkDirFunc documentation for details.
The files are walked in lexical order, which makes the output deterministic but requires WalkDir to read an entire directory into memory before proceeding to walk that directory.
WalkDir does not follow symbolic links.