@@ -12,39 +12,20 @@ package securejoin
12
12
13
13
import (
14
14
"bytes"
15
+ "errors"
15
16
"os"
16
17
"path/filepath"
17
18
"strings"
18
19
"syscall"
19
-
20
- "github.com/pkg/errors"
21
20
)
22
21
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
-
27
22
// IsNotExist tells you if err is an error that implies that either the path
28
23
// accessed does not exist (or path components don't exist). This is
29
24
// effectively a more broad version of os.IsNotExist.
30
25
func 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
-
36
26
// Check that it's not actually an ENOTDIR, which in some cases is a more
37
27
// 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 )
48
29
}
49
30
50
31
// SecureJoinVFS joins the two given path components (similar to Join) except
@@ -68,7 +49,7 @@ func SecureJoinVFS(root, unsafePath string, vfs VFS) (string, error) {
68
49
n := 0
69
50
for unsafePath != "" {
70
51
if n > 255 {
71
- return "" , ErrSymlinkLoop
52
+ return "" , & os. PathError { Op : "SecureJoin" , Path : root + "/" + unsafePath , Err : syscall . ELOOP }
72
53
}
73
54
74
55
// Next path component, p.
0 commit comments