Przeglądaj źródła

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 lat temu
rodzic
commit
8072e62d83
2 zmienionych plików z 4 dodań i 2 usunięć
  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"
 package system // import "github.com/docker/docker/pkg/system"
 
 
 import (
 import (
+	"os"
 	"syscall"
 	"syscall"
 )
 )
 
 
@@ -13,7 +14,7 @@ import (
 func Lstat(path string) (*StatT, error) {
 func Lstat(path string) (*StatT, error) {
 	s := &syscall.Stat_t{}
 	s := &syscall.Stat_t{}
 	if err := syscall.Lstat(path, s); err != nil {
 	if err := syscall.Lstat(path, s); err != nil {
-		return nil, err
+		return nil, &os.PathError{"Lstat", path, err}
 	}
 	}
 	return fromStatT(s)
 	return fromStatT(s)
 }
 }

+ 2 - 1
pkg/system/stat_unix.go

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