Documentation
¶
Overview ¶
Package file writes files atomically, so readers see either the old contents or the new, never a partial write, and finds git projects on disk.
Index ¶
- Variables
- func EnclosingGitProject(path string) (string, error)
- func SkipHidden(_ string, d fs.DirEntry) bool
- func WalkGitProjects(root string, opts GitWalkOptions) ([]string, error)
- func Write(path string, data []byte, perm os.FileMode) error
- func WriteFunc(path string, perm os.FileMode, write func(io.Writer) error) error
- type GitWalkOptions
Constants ¶
This section is empty.
Variables ¶
var ErrNotInGitProject = errors.New("not inside a git project")
ErrNotInGitProject is returned by EnclosingGitProject when no directory above the path is a git project.
Functions ¶
func EnclosingGitProject ¶ added in v0.0.3
EnclosingGitProject returns the root of the git project containing path: the nearest of path and its ancestors with a .git entry, as an absolute path. Within a worktree or submodule, that's the worktree or submodule. path needn't exist.
func SkipHidden ¶ added in v0.0.3
SkipHidden is a GitWalkOptions.Skip that leaves out hidden directories.
func WalkGitProjects ¶ added in v0.0.3
func WalkGitProjects(root string, opts GitWalkOptions) ([]string, error)
WalkGitProjects returns the paths of the git projects at or under root, in lexical order. A project is any directory with a .git entry, which is a file rather than a directory for worktrees and submodules. Projects aren't looked inside, so nested projects and submodules aren't returned, and symlinks below root aren't followed.
An error is returned only if root isn't a readable directory; directories below it that can't be read are left out.
func Write ¶
Write atomically replaces the file at path with data, leaving it with exactly perm whatever the umask and whatever mode an existing file had. It behaves like WriteFunc.
func WriteFunc ¶
WriteFunc atomically replaces the file at path with whatever write writes, leaving it with exactly perm whatever the umask and whatever mode an existing file had.
The content goes to a temporary file in the same directory, which is synced and renamed over path, and then the directory is synced so the rename survives a crash (except on Windows, where directories can't be synced). If write or any step before the rename fails, the temporary file is removed and path is left untouched. If only the directory sync fails, path has already been replaced and the error is still returned.
Types ¶
type GitWalkOptions ¶ added in v0.0.3
type GitWalkOptions struct {
// MaxDepth is how many directories below the root a project can be, so 1
// finds only the root's immediate children. Zero means no limit.
MaxDepth int
// Skip, if set, is asked about each directory below the root before it's
// checked for a project, and returning true leaves it and everything
// under it out.
Skip func(path string, d fs.DirEntry) bool
}
GitWalkOptions limits how far WalkGitProjects looks.