Documentation ¶
Overview ¶
Package fsutil provides filesystem utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
CurrentUser allows for unit test error injection.
var ErrClaimFileBadPattern = errors.New("ClaimFile: pattern must contain exactly one asterisk")
ErrClaimFileBadPattern is thrown when the pattern argument passed to ClaimFile does not contain exactly one asterisk.
Functions ¶
func ClaimFile ¶
ClaimFile takes a directory and a pattern string containing exactly one asterisk (e.g. "a*.log"). It opens a file in that directory, with a filename matching the template, with "*" replaced by a number. That number is one plus the largest of all existing files matching the template. If no such file exists, "*" is replaced by 1. The file is opened for read and write, with permission 0666 (before umask).
For example, if the directory /tmp/elvish contains a1.log, a2.log and a9.log, calling ClaimFile("/tmp/elvish", "a*.log") will open a10.log. If the directory has no files matching the pattern, this same call will open a1.log.
This function is useful for automatically determining unique names for log files. Unique filenames can also be derived by embedding the PID, but using this function preserves the chronical order of the files.
This function is concurrency-safe: it always opens a new, unclaimed file and is not subject to race condition.
func DontSearch ¶
DontSearch determines whether the path to an external command should be taken literally and not searched.
func EachExternal ¶
func EachExternal(f func(string))
EachExternal calls f for each name that can resolve to an external command.
BUG: EachExternal may generate the same command multiple command it it appears in multiple directories in PATH.
BUG: EachExternal doesn't work on Windows since it relies on the execution permission bit, which doesn't exist on Windows.
func GetHome ¶
GetHome finds the home directory of a specified user. When given an empty string, it finds the home directory of the current user.
func Getwd ¶
func Getwd() string
Getwd returns path of the working directory in a format suitable as the prompt.
func IsExecutable ¶
IsExecutable determines whether path refers to an executable file.
Types ¶
This section is empty.