paths

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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 ~/")
)
View Source
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

func ExpandHome(path, home string) (string, error)

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

func OpenRegular(path string) (*os.File, error)

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

func ReadHead(path string, limit int64) ([]byte, error)

ReadHead reads up to limit bytes from the start of the regular file at path, as OpenRegular opens it.

func ReadTail

func ReadTail(path string, limit int64) ([]byte, bool, error)

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

func Resolved(path string) string

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.

func Same

func Same(a, b string) bool

Same reports whether a and b name the same folder: they are equal once cleaned, or once their symbolic links are resolved.

func Tilde

func Tilde(path, home string) string

Tilde shows path relative to home as ~/..., or unchanged when it is outside home or home is unknown.

Types

This section is empty.

Jump to

Keyboard shortcuts

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