Skip to content

Commit

Permalink
Replace shouldSkipSystemError with map lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 29, 2019
1 parent f764e12 commit 7ae3a5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
15 changes: 1 addition & 14 deletions contains.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,8 @@ func Contains(fs Stater, p, prefix string) (bool, error) {
}
// Ignore some syscall.Errnos.
if errno, ok := err.(syscall.Errno); ok {
switch errno {
case syscall.ELOOP:
if _, ignore := ignoreErrnoInContains[errno]; ignore {
goto TryParent
case syscall.EMLINK:
goto TryParent
case syscall.ENAMETOOLONG:
goto TryParent
case syscall.ENOENT:
goto TryParent
case syscall.EOVERFLOW:
goto TryParent
default:
if shouldSkipSystemError(errno) {
goto TryParent
}
}
}
return false, err
Expand Down
12 changes: 8 additions & 4 deletions posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import "syscall"
// HostOSFS is the host-specific OSFS.
var HostOSFS = OSFS

var ignoreErrnoInContains = map[syscall.Errno]struct{}{
syscall.ELOOP: {},
syscall.EMLINK: {},
syscall.ENAMETOOLONG: {},
syscall.ENOENT: {},
syscall.EOVERFLOW: {},
}

// relativizePath, on POSIX systems, just returns path.
func relativizePath(path string) string {
return path
}

func shouldSkipSystemError(err syscall.Errno) bool {
return false
}
13 changes: 9 additions & 4 deletions windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import (
// HostOSFS is the host-specific OSFS.
var HostOSFS = WindowsOSFS{}

var ignoreErrnoInContains = map[syscall.Errno]struct{}{
syscall.ELOOP: {},
syscall.EMLINK: {},
syscall.ENAMETOOLONG: {},
syscall.ENOENT: {},
syscall.EOVERFLOW: {},
windows.ERROR_CANT_RESOLVE_FILENAME: {},
}

// relativizePath, on Windows, strips any leading volume name from path and
// replaces backslashes with slashes.
func relativizePath(path string) string {
Expand All @@ -20,7 +29,3 @@ func relativizePath(path string) string {
}
return filepath.ToSlash(path)
}

func shouldSkipSystemError(err syscall.Errno) bool {
return err == windows.ERROR_CANT_RESOLVE_FILENAME
}

0 comments on commit 7ae3a5d

Please sign in to comment.