summaryrefslogtreecommitdiff
path: root/daemon/archive.go
diff options
context:
space:
mode:
authorBrian Goff <cpuguy83@gmail.com>2017-11-28 23:09:37 -0500
committerBrian Goff <cpuguy83@gmail.com>2018-01-11 21:21:43 -0500
commit87a12421a94faac294079bebc97c8abb4180dde5 (patch)
tree7b8c7ccd021488781ec52b2fde907ddc70fdb12e /daemon/archive.go
parent92309e34e42aec3a0e041403bdd3c4fc0dc20269 (diff)
downloaddocker-87a12421a94faac294079bebc97c8abb4180dde5.tar.gz
Add helpers to create errdef errors
Instead of having to create a bunch of custom error types that are doing nothing but wrapping another error in sub-packages, use a common helper to create errors of the requested type. e.g. instead of re-implementing this over and over: ```go type notFoundError struct { cause error } func(e notFoundError) Error() string { return e.cause.Error() } func(e notFoundError) NotFound() {} func(e notFoundError) Cause() error { return e.cause } ``` Packages can instead just do: ``` errdefs.NotFound(err) ``` Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Diffstat (limited to 'daemon/archive.go')
-rw-r--r--daemon/archive.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/daemon/archive.go b/daemon/archive.go
index c52d3b8509..ddc4b572bd 100644
--- a/daemon/archive.go
+++ b/daemon/archive.go
@@ -5,6 +5,7 @@ import (
"os"
"strings"
+ "github.com/docker/docker/api/errdefs"
"github.com/docker/docker/api/types"
"github.com/docker/docker/container"
"github.com/docker/docker/pkg/archive"
@@ -54,7 +55,7 @@ func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, err
// Make sure an online file-system operation is permitted.
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
- return nil, systemError{err}
+ return nil, errdefs.System(err)
}
data, err := daemon.containerCopy(container, res)
@@ -65,7 +66,7 @@ func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, err
if os.IsNotExist(err) {
return nil, containerFileNotFound{res, name}
}
- return nil, systemError{err}
+ return nil, errdefs.System(err)
}
// ContainerStatPath stats the filesystem resource at the specified path in the
@@ -78,7 +79,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
// Make sure an online file-system operation is permitted.
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
- return nil, systemError{err}
+ return nil, errdefs.System(err)
}
stat, err = daemon.containerStatPath(container, path)
@@ -89,7 +90,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
if os.IsNotExist(err) {
return nil, containerFileNotFound{path, name}
}
- return nil, systemError{err}
+ return nil, errdefs.System(err)
}
// ContainerArchivePath creates an archive of the filesystem resource at the
@@ -103,7 +104,7 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
// Make sure an online file-system operation is permitted.
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
- return nil, nil, systemError{err}
+ return nil, nil, errdefs.System(err)
}
content, stat, err = daemon.containerArchivePath(container, path)
@@ -114,7 +115,7 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
if os.IsNotExist(err) {
return nil, nil, containerFileNotFound{path, name}
}
- return nil, nil, systemError{err}
+ return nil, nil, errdefs.System(err)
}
// ContainerExtractToDir extracts the given archive to the specified location
@@ -131,7 +132,7 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
// Make sure an online file-system operation is permitted.
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
- return systemError{err}
+ return errdefs.System(err)
}
err = daemon.containerExtractToDir(container, path, copyUIDGID, noOverwriteDirNonDir, content)
@@ -142,7 +143,7 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
if os.IsNotExist(err) {
return containerFileNotFound{path, name}
}
- return systemError{err}
+ return errdefs.System(err)
}
// containerStatPath stats the filesystem resource at the specified path in this