Documentation ¶
Overview ¶
Package pathhelper
Index ¶
- Constants
- func AbsWindowsPath(cwd, path string, getFHSPath func(p string) (string, error)) (string, error)
- func Clean(path string, sep byte) string
- func CleanUnixPath(p string) string
- func CleanWindowsPath(p string) string
- func ConvertFSPathToWindowsPath(defaultVolumeName, path string) string
- func EvalLink(linkFile, linkTo string) string
- func FromSlash(path string, sep byte) string
- func IsReservedWindowsName(name string) bool
- func IsReservedWindowsPathChar(c rune) bool
- func IsUnixPathListSeparator(c byte) bool
- func IsUnixSlash(c byte) bool
- func IsWindowsAbs(path string) (b bool)
- func IsWindowsDiskDesignatorChar(c byte) bool
- func IsWindowsPathListSeparator(c byte) bool
- func IsWindowsSlash(c byte) bool
- func JoinUnixPath(elem ...string) string
- func JoinWindowsPath(elem ...string) string
- func LCPP(paths []string) string
- func SplitList(path string, colonSep bool, semiColonSep bool, isSlash CharMatchFunc) []string
- func ToSlash(buf []byte, s string) (ret string, newBuf []byte)
- type CharMatchFunc
Constants ¶
const ( WindowsSlash = '\\' UnixSlash = '/' )
const ( WindowsPathListSeparator = ';' UnixPathListSeparator = ':' )
Variables ¶
This section is empty.
Functions ¶
func AbsWindowsPath ¶
AbsWindowsPath returns absolute path of path with custom cwd cwd SHOULD be a windows absolute path path SHOULD be a relative path (not starting with `[a-zA-Z]:` or `\\`)
It tries to handle three different styles all at once:
- windows native style:
- `foo\bar` and `foo/bar` as path relative
- `\foo` and `/foo` as driver relative
- cygpath style absolute path (`/cygdrive/c`)
- golang io/fs style absolute path for windows (`/[a-zA-Z]/`, e.g. /c/foo)
func Clean ¶
Clean returns the shortest path name equivalent to path by purely lexical processing. It applies the following rules iteratively until no further processing can be done:
- Replace multiple Separator elements with a single one.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path, assuming Separator is '/'.
The returned path ends in a slash only if it represents a root directory, such as "/" on Unix or `C:\` on Windows.
Finally, any occurrences of slash are replaced by Separator.
If the result of this process is an empty string, Clean returns the string ".".
See also Rob Pike, “Lexical File Names in Plan 9 or Getting Dot-Dot Right,” https://9p.io/sys/doc/lexnames.html
func CleanUnixPath ¶
func CleanWindowsPath ¶
func ConvertFSPathToWindowsPath ¶
ConvertFSPathToWindowsPath converts paths like `/c/foo` to absolute windows path `c:/foo` defaultVolumeName is used to resolve path as driver relative path, it's usually obtained by calling filepath.VolumeName, and its value is like `c:`, `\\some-host\path`
func EvalLink ¶
EvalLink returns lintTo's actual path from the point view of linkFile usually used in archive file or non actual os filesystem
For unix style path only
func FromSlash ¶
FromSlash returns the result of replacing each slash ('/') character in path with a separator character. Multiple slashes are replaced by multiple separators.
func IsReservedWindowsName ¶
IsReservedWindowsName returns truen if the name is reserved in windows ref: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
func IsReservedWindowsPathChar ¶
IsReservedWindowsPathChar checks whether c is a reserved character for windows path ref: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
func IsUnixPathListSeparator ¶
IsUnixPathListSeparator returns true when c is colon
func IsWindowsAbs ¶
IsWindowsAbs reports whether the path is absolute on windows the path is considered absolute as following cases - reserved windows names (e.g. COM1) - starts with `\\<some-host>\<share>` (UNC path) - starts with `C:\` (driver absolute path) - starts with `\` or `/`
func IsWindowsDiskDesignatorChar ¶
IsWindowsDiskDesignatorChar returns true when c matches [a-zA-Z]
func IsWindowsPathListSeparator ¶
IsWindowsPathListSeparator returns true when c is colon or semi-colon
func IsWindowsSlash ¶
IsWindowsSlash returns true when c is slash or back slash
func JoinUnixPath ¶
func JoinWindowsPath ¶
func SplitList ¶
func SplitList( path string, colonSep bool, semiColonSep bool, isSlash CharMatchFunc, ) []string
SplitList is like filepath.SplitList, but caller controls whether take colon and/or semi-colon as path separators
it also handles double-quoted path segments
NOTE for windows path lists:
behavior differences from win32: - when colonIsPathSeparator is true, "C:tmp.txt" will be splited into `C` and `tmp.txt` instead of keeping it as like win32's behavior: a file named "tmp.txt" in the current directory on drive C
NOTE for unix style path list:
when colonIsPathSeparator is true (most of the case) `[a-zA-Z]:/` in middle of the path list followd by an absolute path will be joined with next path segment e.g. `/root/bin:c:/foo` becomes `/root/bin`, `c:/foo` so it's preferable to avoid single character relative path in the path list
func ToSlash ¶ added in v0.10.0
ToSlash replaces all backslashes to slashes in s as ret
unlike ToSlash funcs from std path/filepath package, this function always does the replacement no matter what platform currently running on
the returned newBuf should be used for following calls if both "len(s) > len(buf)" and "s contains backslash" are true