mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: Daemon.ContainerStatPath, ContainerArchivePath: minor refactor
- remove named error-returns - make error-handling slightly more idiomatic (check for non-nil errors) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -10,13 +10,13 @@ import (
|
||||
|
||||
// ContainerStatPath stats the filesystem resource at the specified path in the
|
||||
// container identified by the given name.
|
||||
func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *container.PathStat, err error) {
|
||||
func (daemon *Daemon) ContainerStatPath(name string, path string) (*container.PathStat, error) {
|
||||
ctr, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stat, err = daemon.containerStatPath(ctr, path)
|
||||
stat, err := daemon.containerStatPath(ctr, path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, containerFileNotFound{path, name}
|
||||
@@ -33,7 +33,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *contain
|
||||
// ContainerArchivePath creates an archive of the filesystem resource at the
|
||||
// specified path in the container identified by the given name. Returns a
|
||||
// tar archive of the resource and whether it was a directory or a single file.
|
||||
func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, err error) {
|
||||
func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *container.PathStat, _ error) {
|
||||
ctr, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
// containerStatPath stats the filesystem resource at the specified path in this
|
||||
// container. Returns stat info about the resource.
|
||||
func (daemon *Daemon) containerStatPath(container *container.Container, path string) (stat *containertypes.PathStat, err error) {
|
||||
func (daemon *Daemon) containerStatPath(container *container.Container, path string) (*containertypes.PathStat, error) {
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
||||
@@ -36,11 +36,11 @@ func (daemon *Daemon) containerStatPath(container *container.Container, path str
|
||||
// containerArchivePath creates an archive of the filesystem resource at the specified
|
||||
// path in this container. Returns a tar archive of the resource and stat info
|
||||
// about the resource.
|
||||
func (daemon *Daemon) containerArchivePath(container *container.Container, path string) (content io.ReadCloser, stat *containertypes.PathStat, err error) {
|
||||
func (daemon *Daemon) containerArchivePath(container *container.Container, path string) (content io.ReadCloser, stat *containertypes.PathStat, retErr error) {
|
||||
container.Lock()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if retErr != nil {
|
||||
// Wait to unlock the container until the archive is fully read
|
||||
// (see the ReadCloseWrapper func below) or if there is an error
|
||||
// before that occurs.
|
||||
@@ -54,8 +54,8 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
cfs.Close()
|
||||
if retErr != nil {
|
||||
_ = cfs.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
// containerStatPath stats the filesystem resource at the specified path in this
|
||||
// container. Returns stat info about the resource.
|
||||
func (daemon *Daemon) containerStatPath(container *container.Container, path string) (stat *containertypes.PathStat, err error) {
|
||||
func (daemon *Daemon) containerStatPath(container *container.Container, path string) (*containertypes.PathStat, error) {
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
||||
@@ -26,12 +26,12 @@ func (daemon *Daemon) containerStatPath(container *container.Container, path str
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = daemon.Mount(container); err != nil {
|
||||
if err := daemon.Mount(container); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer daemon.Unmount(container)
|
||||
|
||||
err = daemon.mountVolumes(container)
|
||||
err := daemon.mountVolumes(container)
|
||||
defer container.DetachAndUnmount(daemon.LogVolumeEvent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -51,11 +51,11 @@ func (daemon *Daemon) containerStatPath(container *container.Container, path str
|
||||
// containerArchivePath creates an archive of the filesystem resource at the specified
|
||||
// path in this container. Returns a tar archive of the resource and stat info
|
||||
// about the resource.
|
||||
func (daemon *Daemon) containerArchivePath(container *container.Container, path string) (content io.ReadCloser, stat *containertypes.PathStat, err error) {
|
||||
func (daemon *Daemon) containerArchivePath(container *container.Container, path string) (content io.ReadCloser, stat *containertypes.PathStat, retErr error) {
|
||||
container.Lock()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if retErr != nil {
|
||||
// Wait to unlock the container until the archive is fully read
|
||||
// (see the ReadCloseWrapper func below) or if there is an error
|
||||
// before that occurs.
|
||||
@@ -68,12 +68,12 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if err = daemon.Mount(container); err != nil {
|
||||
if err := daemon.Mount(container); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if retErr != nil {
|
||||
// unmount any volumes
|
||||
container.DetachAndUnmount(daemon.LogVolumeEvent)
|
||||
// unmount the container's rootfs
|
||||
@@ -81,7 +81,7 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
|
||||
}
|
||||
}()
|
||||
|
||||
if err = daemon.mountVolumes(container); err != nil {
|
||||
if err := daemon.mountVolumes(container); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -223,14 +223,14 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) containerCopy(container *container.Container, resource string) (rc io.ReadCloser, err error) {
|
||||
func (daemon *Daemon) containerCopy(container *container.Container, resource string) (_ io.ReadCloser, retErr error) {
|
||||
if resource[0] == '/' || resource[0] == '\\' {
|
||||
resource = resource[1:]
|
||||
}
|
||||
container.Lock()
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if retErr != nil {
|
||||
// Wait to unlock the container until the archive is fully read
|
||||
// (see the ReadCloseWrapper func below) or if there is an error
|
||||
// before that occurs.
|
||||
@@ -248,7 +248,7 @@ func (daemon *Daemon) containerCopy(container *container.Container, resource str
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if retErr != nil {
|
||||
// unmount any volumes
|
||||
container.DetachAndUnmount(daemon.LogVolumeEvent)
|
||||
// unmount the container's rootfs
|
||||
|
||||
Reference in New Issue
Block a user