Documentation ¶
Overview ¶
Package turbopath teaches the Go type system about six different types of paths: - AbsoluteSystemPath - RelativeSystemPath - AnchoredSystemPath - AbsoluteUnixPath - RelativeUnixPath - AnchoredUnixPath
Between these two things it is assumed that we will be able to reasonably describe file paths being used within the system and have the type system enforce correctness instead of relying upon runtime code to accomplish the task.
Absolute paths are, "absolute, including volume root." They are not portable between System and Unix.
Relative paths are simply arbitrary path segments using a particular path delimiter. They are portable between System and Unix.
Anchored paths are, "absolute, starting at a particular root." They are not aware of *what* their anchor is. It could be a repository, an `os.dirFS`, a package, `cwd`, or more. They are stored *without* a preceding delimiter for compatibility with `io/fs`. They are portable between System and Unix.
In some future world everything in here can be optimized out at compile time. Everything is either `string` or `[]string`
Much of this is dreadfully repetitive because of intentional limitations in the Go type system.
Index ¶
- func FindupFrom(name, dir string) (string, error)
- type AbsoluteSystemPath
- func (p AbsoluteSystemPath) Base() string
- func (p AbsoluteSystemPath) ContainsPath(other AbsoluteSystemPath) (bool, error)
- func (p AbsoluteSystemPath) Create() (*os.File, error)
- func (p AbsoluteSystemPath) Dir() AbsoluteSystemPath
- func (p AbsoluteSystemPath) DirExists() bool
- func (p AbsoluteSystemPath) EnsureDir() error
- func (p AbsoluteSystemPath) EvalSymlinks() (AbsoluteSystemPath, error)
- func (p AbsoluteSystemPath) Exists() bool
- func (p AbsoluteSystemPath) Ext() string
- func (p AbsoluteSystemPath) FileExists() bool
- func (p AbsoluteSystemPath) Findup(name RelativeSystemPath) (AbsoluteSystemPath, error)
- func (p AbsoluteSystemPath) HasPrefix(prefix AbsoluteSystemPath) bool
- func (p AbsoluteSystemPath) Join(additional ...RelativeSystemPath) AbsoluteSystemPath
- func (p AbsoluteSystemPath) Lchmod(mode os.FileMode) error
- func (p AbsoluteSystemPath) Lstat() (os.FileInfo, error)
- func (p AbsoluteSystemPath) Mkdir(perm os.FileMode) error
- func (p AbsoluteSystemPath) MkdirAll(perm os.FileMode) error
- func (p AbsoluteSystemPath) MkdirAllMode(mode os.FileMode) error
- func (p AbsoluteSystemPath) Open() (*os.File, error)
- func (p AbsoluteSystemPath) OpenFile(flags int, mode os.FileMode) (*os.File, error)
- func (p AbsoluteSystemPath) PathTo(other AbsoluteSystemPath) (string, error)
- func (p AbsoluteSystemPath) ReadFile() ([]byte, error)
- func (p AbsoluteSystemPath) Readlink() (string, error)
- func (p AbsoluteSystemPath) RelativePathString(path string) (string, error)
- func (p AbsoluteSystemPath) RelativeTo(basePath AbsoluteSystemPath) (AnchoredSystemPath, error)
- func (p AbsoluteSystemPath) Remove() error
- func (p AbsoluteSystemPath) RemoveAll() error
- func (p AbsoluteSystemPath) Rename(dest AbsoluteSystemPath) error
- func (p AbsoluteSystemPath) Stat() (os.FileInfo, error)
- func (p AbsoluteSystemPath) Symlink(target string) error
- func (p AbsoluteSystemPath) ToString() string
- func (p AbsoluteSystemPath) ToStringDuringMigration() string
- func (p AbsoluteSystemPath) UntypedJoin(args ...string) AbsoluteSystemPath
- func (p AbsoluteSystemPath) VolumeName() string
- func (p AbsoluteSystemPath) WriteFile(contents []byte, mode os.FileMode) error
- type AnchoredSystemPath
- func (p AnchoredSystemPath) Dir() AnchoredSystemPath
- func (p AnchoredSystemPath) HasPrefix(prefix AnchoredSystemPath) bool
- func (p AnchoredSystemPath) Join(additional ...RelativeSystemPath) AnchoredSystemPath
- func (p AnchoredSystemPath) RelativeTo(basePath AnchoredSystemPath) (AnchoredSystemPath, error)
- func (p AnchoredSystemPath) RestoreAnchor(anchor AbsoluteSystemPath) AbsoluteSystemPath
- func (p AnchoredSystemPath) ToString() string
- func (p AnchoredSystemPath) ToStringDuringMigration() string
- func (p AnchoredSystemPath) ToSystemPath() AnchoredSystemPath
- func (p AnchoredSystemPath) ToUnixPath() AnchoredUnixPath
- type AnchoredUnixPath
- type AnchoredUnixPathArray
- type RelativeSystemPath
- type RelativeSystemPathArray
- type RelativeUnixPath
- type RelativeUnixPathArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindupFrom ¶
FindupFrom Recursively finds a file by walking up parents in the file tree starting from a specific directory.
Types ¶
type AbsoluteSystemPath ¶
type AbsoluteSystemPath string
AbsoluteSystemPath is a root-relative path using system separators.
func AbsoluteSystemPathFromUpstream ¶
func AbsoluteSystemPathFromUpstream(path string) AbsoluteSystemPath
AbsoluteSystemPathFromUpstream takes a path string and casts it to an AbsoluteSystemPath without checking. If the input to this function is not an AbsoluteSystemPath it will result in downstream errors.
func (AbsoluteSystemPath) Base ¶
func (p AbsoluteSystemPath) Base() string
Base implements filepath.Base for an absolute path
func (AbsoluteSystemPath) ContainsPath ¶
func (p AbsoluteSystemPath) ContainsPath(other AbsoluteSystemPath) (bool, error)
ContainsPath returns true if this absolute path is a parent of the argument.
func (AbsoluteSystemPath) Create ¶
func (p AbsoluteSystemPath) Create() (*os.File, error)
Create is the AbsoluteSystemPath wrapper for os.Create
func (AbsoluteSystemPath) Dir ¶
func (p AbsoluteSystemPath) Dir() AbsoluteSystemPath
Dir implements filepath.Dir() for an AbsoluteSystemPath
func (AbsoluteSystemPath) DirExists ¶
func (p AbsoluteSystemPath) DirExists() bool
DirExists returns true if the given path exists and is a directory.
func (AbsoluteSystemPath) EnsureDir ¶
func (p AbsoluteSystemPath) EnsureDir() error
EnsureDir ensures that the directory containing this file exists
func (AbsoluteSystemPath) EvalSymlinks ¶
func (p AbsoluteSystemPath) EvalSymlinks() (AbsoluteSystemPath, error)
EvalSymlinks implements filepath.EvalSymlinks for absolute path
func (AbsoluteSystemPath) Exists ¶
func (p AbsoluteSystemPath) Exists() bool
Exists returns true if the given path exists.
func (AbsoluteSystemPath) Ext ¶
func (p AbsoluteSystemPath) Ext() string
Ext implements filepath.Ext(p) for an absolute path
func (AbsoluteSystemPath) FileExists ¶
func (p AbsoluteSystemPath) FileExists() bool
FileExists returns true if the given path exists and is a file.
func (AbsoluteSystemPath) Findup ¶
func (p AbsoluteSystemPath) Findup(name RelativeSystemPath) (AbsoluteSystemPath, error)
Findup checks all parent directories for a file.
func (AbsoluteSystemPath) HasPrefix ¶
func (p AbsoluteSystemPath) HasPrefix(prefix AbsoluteSystemPath) bool
HasPrefix is strings.HasPrefix for paths, ensuring that it matches on separator boundaries. This does NOT perform Clean in advance.
func (AbsoluteSystemPath) Join ¶
func (p AbsoluteSystemPath) Join(additional ...RelativeSystemPath) AbsoluteSystemPath
Join appends relative path segments to this AbsoluteSystemPath.
func (AbsoluteSystemPath) Lchmod ¶
func (p AbsoluteSystemPath) Lchmod(mode os.FileMode) error
Lchmod changes the mode of a file not following symlinks.
func (AbsoluteSystemPath) Lstat ¶
func (p AbsoluteSystemPath) Lstat() (os.FileInfo, error)
Lstat implements os.Lstat for absolute path
func (AbsoluteSystemPath) Mkdir ¶
func (p AbsoluteSystemPath) Mkdir(perm os.FileMode) error
Mkdir implements os.Mkdir(p, perm)
func (AbsoluteSystemPath) MkdirAll ¶
func (p AbsoluteSystemPath) MkdirAll(perm os.FileMode) error
MkdirAll implements os.MkdirAll(p, perm)
func (AbsoluteSystemPath) MkdirAllMode ¶
func (p AbsoluteSystemPath) MkdirAllMode(mode os.FileMode) error
MkdirAllMode Create directory at path and all necessary parents ensuring that path has the correct mode set
func (AbsoluteSystemPath) Open ¶
func (p AbsoluteSystemPath) Open() (*os.File, error)
Open implements os.Open(p) for an AbsoluteSystemPath
func (AbsoluteSystemPath) PathTo ¶
func (p AbsoluteSystemPath) PathTo(other AbsoluteSystemPath) (string, error)
PathTo returns the relative path between two absolute paths This should likely eventually return an AnchoredSystemPath
func (AbsoluteSystemPath) ReadFile ¶
func (p AbsoluteSystemPath) ReadFile() ([]byte, error)
ReadFile reads the contents of the specified file
func (AbsoluteSystemPath) Readlink ¶
func (p AbsoluteSystemPath) Readlink() (string, error)
Readlink implements os.Readlink(p) for an absolute path
func (AbsoluteSystemPath) RelativePathString ¶
func (p AbsoluteSystemPath) RelativePathString(path string) (string, error)
RelativePathString returns the relative path from this AbsoluteSystemPath to another absolute path in string form as a string
func (AbsoluteSystemPath) RelativeTo ¶
func (p AbsoluteSystemPath) RelativeTo(basePath AbsoluteSystemPath) (AnchoredSystemPath, error)
RelativeTo calculates the relative path between two `AbsoluteSystemPath`s.
func (AbsoluteSystemPath) Remove ¶
func (p AbsoluteSystemPath) Remove() error
Remove removes the file or (empty) directory at the given path
func (AbsoluteSystemPath) RemoveAll ¶
func (p AbsoluteSystemPath) RemoveAll() error
RemoveAll implements os.RemoveAll for absolute paths.
func (AbsoluteSystemPath) Rename ¶
func (p AbsoluteSystemPath) Rename(dest AbsoluteSystemPath) error
Rename implements os.Rename(p, dest) for absolute paths
func (AbsoluteSystemPath) Stat ¶
func (p AbsoluteSystemPath) Stat() (os.FileInfo, error)
Stat implements os.Stat for absolute path
func (AbsoluteSystemPath) Symlink ¶
func (p AbsoluteSystemPath) Symlink(target string) error
Symlink implements os.Symlink(target, p) for absolute path
func (AbsoluteSystemPath) ToString ¶
func (p AbsoluteSystemPath) ToString() string
ToString returns a string represenation of this Path. Used for interfacing with APIs that require a string.
func (AbsoluteSystemPath) ToStringDuringMigration ¶
func (p AbsoluteSystemPath) ToStringDuringMigration() string
ToStringDuringMigration returns a string representation of this path. These instances should eventually be removed.
func (AbsoluteSystemPath) UntypedJoin ¶
func (p AbsoluteSystemPath) UntypedJoin(args ...string) AbsoluteSystemPath
UntypedJoin is a Join that does not constrain the type of the arguments. This enables you to pass in strings, but does not protect you from garbage in.
func (AbsoluteSystemPath) VolumeName ¶
func (p AbsoluteSystemPath) VolumeName() string
VolumeName returns the volume of the specified path
type AnchoredSystemPath ¶
type AnchoredSystemPath string
AnchoredSystemPath is a path stemming from a specified root using system separators.
func AnchoredSystemPathFromUpstream ¶
func AnchoredSystemPathFromUpstream(path string) AnchoredSystemPath
AnchoredSystemPathFromUpstream takes a path string and casts it to an AnchoredSystemPath without checking. If the input to this function is not an AnchoredSystemPath it will result in downstream errors.
func (AnchoredSystemPath) Dir ¶
func (p AnchoredSystemPath) Dir() AnchoredSystemPath
Dir returns filepath.Dir for the path.
func (AnchoredSystemPath) HasPrefix ¶
func (p AnchoredSystemPath) HasPrefix(prefix AnchoredSystemPath) bool
HasPrefix is strings.HasPrefix for paths, ensuring that it matches on separator boundaries. This does NOT perform Clean in advance.
func (AnchoredSystemPath) Join ¶
func (p AnchoredSystemPath) Join(additional ...RelativeSystemPath) AnchoredSystemPath
Join appends relative path segments to this AnchoredSystemPath.
func (AnchoredSystemPath) RelativeTo ¶
func (p AnchoredSystemPath) RelativeTo(basePath AnchoredSystemPath) (AnchoredSystemPath, error)
RelativeTo calculates the relative path between two AnchoredSystemPath`s.
func (AnchoredSystemPath) RestoreAnchor ¶
func (p AnchoredSystemPath) RestoreAnchor(anchor AbsoluteSystemPath) AbsoluteSystemPath
RestoreAnchor prefixes the AnchoredSystemPath with its anchor to return an AbsoluteSystemPath.
func (AnchoredSystemPath) ToString ¶
func (p AnchoredSystemPath) ToString() string
ToString returns a string represenation of this Path. Used for interfacing with APIs that require a string.
func (AnchoredSystemPath) ToStringDuringMigration ¶
func (p AnchoredSystemPath) ToStringDuringMigration() string
ToStringDuringMigration returns the string representation of this path, and is for use in situations where we expect a future path migration to remove the need for the string representation
func (AnchoredSystemPath) ToSystemPath ¶
func (p AnchoredSystemPath) ToSystemPath() AnchoredSystemPath
ToSystemPath returns itself.
func (AnchoredSystemPath) ToUnixPath ¶
func (p AnchoredSystemPath) ToUnixPath() AnchoredUnixPath
ToUnixPath converts a AnchoredSystemPath to a AnchoredUnixPath.
type AnchoredUnixPath ¶
type AnchoredUnixPath string
AnchoredUnixPath is a path stemming from a specified root using Unix `/` separators.
func AnchoredUnixPathFromUpstream ¶
func AnchoredUnixPathFromUpstream(path string) AnchoredUnixPath
AnchoredUnixPathFromUpstream takes a path string and casts it to an AnchoredUnixPath without checking. If the input to this function is not an AnchoredUnixPath it will result in downstream errors.
func CheckedToAnchoredUnixPath ¶
func CheckedToAnchoredUnixPath(s string) (AnchoredUnixPath, error)
CheckedToAnchoredUnixPath inspects a string and determines if it is a relative path.
func (AnchoredUnixPath) Join ¶
func (p AnchoredUnixPath) Join(additional ...RelativeUnixPath) AnchoredUnixPath
Join appends relative path segments to this RelativeUnixPath.
func (AnchoredUnixPath) ToString ¶
func (p AnchoredUnixPath) ToString() string
ToString returns a string represenation of this Path. Used for interfacing with APIs that require a string.
func (AnchoredUnixPath) ToSystemPath ¶
func (p AnchoredUnixPath) ToSystemPath() AnchoredSystemPath
ToSystemPath converts a AnchoredUnixPath to a AnchoredSystemPath.
func (AnchoredUnixPath) ToUnixPath ¶
func (p AnchoredUnixPath) ToUnixPath() AnchoredUnixPath
ToUnixPath returns itself.
type AnchoredUnixPathArray ¶
type AnchoredUnixPathArray []AnchoredUnixPath
AnchoredUnixPathArray is a type used to enable transform operations on arrays of paths.
func (AnchoredUnixPathArray) ToSystemPathArray ¶
func (source AnchoredUnixPathArray) ToSystemPathArray() []AnchoredSystemPath
ToSystemPathArray enables ergonomic operations on arrays of AnchoredUnixPath
type RelativeSystemPath ¶
type RelativeSystemPath string
RelativeSystemPath is a relative path using system separators.
func CheckedToRelativeSystemPath ¶
func CheckedToRelativeSystemPath(s string) (RelativeSystemPath, error)
CheckedToRelativeSystemPath inspects a string and determines if it is a relative path.
func MakeRelativeSystemPath ¶
func MakeRelativeSystemPath(segments ...string) RelativeSystemPath
MakeRelativeSystemPath joins the given segments in a system-appropriate way
func RelativeSystemPathFromUpstream ¶
func RelativeSystemPathFromUpstream(path string) RelativeSystemPath
RelativeSystemPathFromUpstream takes a path string and casts it to an RelativeSystemPath without checking. If the input to this function is not an RelativeSystemPath it will result in downstream errors.
func (RelativeSystemPath) Join ¶
func (p RelativeSystemPath) Join(additional ...RelativeSystemPath) RelativeSystemPath
Join appends relative path segments to this RelativeSystemPath.
func (RelativeSystemPath) ToString ¶
func (p RelativeSystemPath) ToString() string
ToString returns a string represenation of this Path. Used for interfacing with APIs that require a string.
func (RelativeSystemPath) ToSystemPath ¶
func (p RelativeSystemPath) ToSystemPath() RelativeSystemPath
ToSystemPath returns itself.
func (RelativeSystemPath) ToUnixPath ¶
func (p RelativeSystemPath) ToUnixPath() RelativeUnixPath
ToUnixPath converts from RelativeSystemPath to RelativeUnixPath.
type RelativeSystemPathArray ¶
type RelativeSystemPathArray []RelativeSystemPath
RelativeSystemPathArray is a type used to enable transform operations on arrays of paths.
func (RelativeSystemPathArray) ToStringArray ¶
func (source RelativeSystemPathArray) ToStringArray() []string
ToStringArray enables ergonomic operations on arrays of RelativeSystemPath
type RelativeUnixPath ¶
type RelativeUnixPath string
RelativeUnixPath is a relative path using Unix `/` separators.
func RelativeUnixPathFromUpstream ¶
func RelativeUnixPathFromUpstream(path string) RelativeUnixPath
RelativeUnixPathFromUpstream takes a path string and casts it to an RelativeUnixPath without checking. If the input to this function is not an RelativeUnixPath it will result in downstream errors.
func (RelativeUnixPath) Join ¶
func (p RelativeUnixPath) Join(additional ...RelativeUnixPath) RelativeUnixPath
Join appends relative path segments to this RelativeUnixPath.
func (RelativeUnixPath) ToString ¶
func (p RelativeUnixPath) ToString() string
ToString returns a string represenation of this Path. Used for interfacing with APIs that require a string.
func (RelativeUnixPath) ToSystemPath ¶
func (p RelativeUnixPath) ToSystemPath() RelativeSystemPath
ToSystemPath converts a RelativeUnixPath to a RelativeSystemPath.
func (RelativeUnixPath) ToUnixPath ¶
func (p RelativeUnixPath) ToUnixPath() RelativeUnixPath
ToUnixPath converts a RelativeUnixPath to a RelativeSystemPath.
type RelativeUnixPathArray ¶
type RelativeUnixPathArray []RelativeUnixPath
RelativeUnixPathArray is a type used to enable transform operations on arrays of paths.
func (RelativeUnixPathArray) ToStringArray ¶
func (source RelativeUnixPathArray) ToStringArray() []string
ToStringArray enables ergonomic operations on arrays of RelativeUnixPath