Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatcuk committed Aug 2, 2019
1 parent d850821 commit 2437321
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions doublestar.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,19 @@ func Glob(pattern string) (matches []string, err error) {
return nil, nil
}

// On Windows systems, this will return the drive name ('C:'), on others,
// it will return an empty string.
// On Windows systems, this will return the drive name ('C:') for filesystem
// paths, or \\<server>\<share> for UNC paths. On other systems, it will
// return an empty string. Since absolute paths on non-Windows systems start
// with a slash, patternComponent[0] == volumeName will return true for both
// absolute Windows paths and absolute non-Windows paths, but we need a
// separate check for UNC paths.
volumeName := filepath.VolumeName(pattern)

// On Windows: VolumeName returns \\<server>\<first component> for \\ prefixed patterns.

// If the first pattern component is equal to the volume name, then the
// pattern is an absolute path.
startComponentIndex := 1
isWindowsUNC := false

if strings.HasPrefix(pattern, "\\\\") {
startComponentIndex = 4
isWindowsUNC = true
}

isWindowsUNC := strings.HasPrefix(pattern, `\\`)
if isWindowsUNC || patternComponents[0] == volumeName {
startComponentIndex := 1
if isWindowsUNC {
startComponentIndex = 4
}
return doGlob(fmt.Sprintf("%s%s", volumeName, string(os.PathSeparator)), patternComponents[startComponentIndex:], matches)
}

Expand Down

0 comments on commit 2437321

Please sign in to comment.