@@ -12,39 +12,20 @@ package securejoin
1212
1313import (
1414 "bytes"
15+ "errors"
1516 "os"
1617 "path/filepath"
1718 "strings"
1819 "syscall"
19-
20- "github.com/pkg/errors"
2120)
2221
23- // ErrSymlinkLoop is returned by SecureJoinVFS when too many symlinks have been
24- // evaluated in attempting to securely join the two given paths.
25- var ErrSymlinkLoop = errors .Wrap (syscall .ELOOP , "secure join" )
26-
2722// IsNotExist tells you if err is an error that implies that either the path
2823// accessed does not exist (or path components don't exist). This is
2924// effectively a more broad version of os.IsNotExist.
3025func IsNotExist (err error ) bool {
31- // If it's a bone-fide ENOENT just bail.
32- if os .IsNotExist (errors .Cause (err )) {
33- return true
34- }
35-
3626 // Check that it's not actually an ENOTDIR, which in some cases is a more
3727 // convoluted case of ENOENT (usually involving weird paths).
38- var errno error
39- switch err := errors .Cause (err ).(type ) {
40- case * os.PathError :
41- errno = err .Err
42- case * os.LinkError :
43- errno = err .Err
44- case * os.SyscallError :
45- errno = err .Err
46- }
47- return errno == syscall .ENOTDIR || errno == syscall .ENOENT
28+ return errors .Is (err , os .ErrNotExist ) || errors .Is (err , syscall .ENOTDIR ) || errors .Is (err , syscall .ENOENT )
4829}
4930
5031// SecureJoinVFS joins the two given path components (similar to Join) except
@@ -68,7 +49,7 @@ func SecureJoinVFS(root, unsafePath string, vfs VFS) (string, error) {
6849 n := 0
6950 for unsafePath != "" {
7051 if n > 255 {
71- return "" , ErrSymlinkLoop
52+ return "" , & os. PathError { Op : "SecureJoin" , Path : root + "/" + unsafePath , Err : syscall . ELOOP }
7253 }
7354
7455 // Next path component, p.
0 commit comments