From c78af57e21f74319228d0398cc09c847726f193e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 27 Sep 2022 22:17:27 +0200 Subject: [PATCH] daemon: replace ErrVolumeReadonly with errdefs It was only used in a single location, and the ErrVolumeReadonly was not checked for, or used as a sentinel error. This error was introduced in c32dde5baadc8c472666ef9d5cead13ab6de28ea. It was never used as a sentinel error, but from that commit, it looks like it was added as a package variable to mirror already existing errors defined at the package level. This patch removes the exported variable, and replaces the error with an errdefs.InvalidParameter(), so that the API also returns the correct (400) status code. Signed-off-by: Sebastiaan van Stijn --- daemon/archive_unix.go | 4 +++- daemon/volumes.go | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/daemon/archive_unix.go b/daemon/archive_unix.go index 863788d72d..7a5e29905a 100644 --- a/daemon/archive_unix.go +++ b/daemon/archive_unix.go @@ -5,7 +5,9 @@ package daemon // import "github.com/docker/docker/daemon" import ( "github.com/docker/docker/container" + "github.com/docker/docker/errdefs" volumemounts "github.com/docker/docker/volume/mounts" + "github.com/pkg/errors" ) // checkIfPathIsInAVolume checks if the path is in a volume. If it is, it @@ -19,7 +21,7 @@ func checkIfPathIsInAVolume(container *container.Container, absPath string) (boo if mnt.RW { break } - return false, ErrVolumeReadonly + return false, errdefs.InvalidParameter(errors.New("mounted volume is marked read-only")) } } return toVolume, nil diff --git a/daemon/volumes.go b/daemon/volumes.go index 6148018aff..6e17e221c6 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -21,12 +21,6 @@ import ( "github.com/sirupsen/logrus" ) -var ( - // ErrVolumeReadonly is used to signal an error when trying to copy data into - // a volume mount that is not writable. - ErrVolumeReadonly = errors.New("mounted volume is marked read-only") -) - type mounts []container.Mount // Len returns the number of mounts. Used in sorting.