Bläddra i källkod

pkg/system/stat_unix: wrap errors in PathError

syscall.Stat (and Lstat), unlike functions from os pkg,
return "raw" errors (like EPERM or EINVAL), and those are
propagated up the function call stack unchanged, and gets
logged and/or returned to the user as is.

Wrap those into os.PathError{} so the error message will
at least have function name and file name.

Note we use Capitalized function names to distinguish
between functions in os and ours.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Kir Kolyshkin 6 år sedan
förälder
incheckning
8072e62d83
2 ändrade filer med 4 tillägg och 2 borttagningar
  1. 2 1
      pkg/system/lstat_unix.go
  2. 2 1
      pkg/system/stat_unix.go

+ 2 - 1
pkg/system/lstat_unix.go

@@ -3,6 +3,7 @@
 package system // import "github.com/docker/docker/pkg/system"
 
 import (
+	"os"
 	"syscall"
 )
 
@@ -13,7 +14,7 @@ import (
 func Lstat(path string) (*StatT, error) {
 	s := &syscall.Stat_t{}
 	if err := syscall.Lstat(path, s); err != nil {
-		return nil, err
+		return nil, &os.PathError{"Lstat", path, err}
 	}
 	return fromStatT(s)
 }

+ 2 - 1
pkg/system/stat_unix.go

@@ -3,6 +3,7 @@
 package system // import "github.com/docker/docker/pkg/system"
 
 import (
+	"os"
 	"syscall"
 )
 
@@ -59,7 +60,7 @@ func (s StatT) IsDir() bool {
 func Stat(path string) (*StatT, error) {
 	s := &syscall.Stat_t{}
 	if err := syscall.Stat(path, s); err != nil {
-		return nil, err
+		return nil, &os.PathError{"Stat", path, err}
 	}
 	return fromStatT(s)
 }