Documentation
¶
Overview ¶
Package paths turns the paths a user types into absolute ones and back: a leading ~ expands to the home directory, and a path under home is shown as ~/.... It also opens the files a repository or an agent controls (OpenRegular, ReadHead, ReadTail), reading only a regular file, or a link to one, so a named pipe put there never hangs a read.
Index ¶
- Variables
- func ExpandHome(path, home string) (string, error)
- func OpenRegular(path string) (*os.File, error)
- func ReadHead(path string, limit int64) ([]byte, error)
- func ReadTail(path string, limit int64) ([]byte, bool, error)
- func Resolved(path string) string
- func Same(a, b string) bool
- func Tilde(path, home string) string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmpty is returned for an empty path. ErrEmpty = errors.New("path is empty") // ErrNoHome is returned when a path starts with ~ but the home directory is unknown. ErrNoHome = errors.New("home directory is unknown") // ErrRelative is returned for a path that is neither absolute nor ~-relative. ErrRelative = errors.New("path must be absolute or start with ~/") )
var ErrNotRegular = errors.New("not a regular file")
ErrNotRegular is returned for a path that is there but isn't a regular file, such as a folder, a named pipe, or a device, which is never read.
Functions ¶
func ExpandHome ¶
ExpandHome turns a typed path into an absolute, cleaned one: surrounding space is trimmed, and a leading ~ (alone or followed by /) becomes home. Any other path must already be absolute; "~user/..." is not expanded and so is refused as relative.
func OpenRegular ¶
OpenRegular opens the regular file at path to read, following a link, and refuses anything else with ErrNotRegular. A path that isn't one is never opened, and one swapped for a pipe or a device since it was looked at is opened without waiting, as opening a pipe that nothing writes to otherwise would, and refused once open. Every file a repository or an agent controls is read through it, so none can hang a read.
func ReadHead ¶
ReadHead reads up to limit bytes from the start of the regular file at path, as OpenRegular opens it.
func ReadTail ¶
ReadTail reads up to limit bytes from the end of the regular file at path, as OpenRegular opens it, and reports whether that is less than the whole file. A file that shrinks while it is read gives the bytes that were there.
func Resolved ¶
Resolved returns path cleaned, with symbolic links resolved. A path that does not exist is resolved through its nearest existing parent, so it still matches the form the OS and git report for it; a path with no existing parent is only cleaned.
Types ¶
This section is empty.