2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-05-13 01:21:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2018-01-11 19:53:06 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
2015-05-13 01:21:26 +00:00
|
|
|
)
|
|
|
|
|
2015-07-16 21:14:58 +00:00
|
|
|
// ContainerCopy performs a deprecated operation of archiving the resource at
|
2015-12-13 16:00:39 +00:00
|
|
|
// the specified path in the container identified by the given name.
|
2015-09-29 17:51:40 +00:00
|
|
|
func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
|
2019-08-09 12:10:07 +00:00
|
|
|
ctr, err := daemon.GetContainer(name)
|
2015-05-13 01:21:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-09 12:10:07 +00:00
|
|
|
data, err := daemon.containerCopy(ctr, res)
|
2017-07-19 14:20:13 +00:00
|
|
|
if err == nil {
|
|
|
|
return data, nil
|
2017-03-15 18:29:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 14:20:13 +00:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, containerFileNotFound{res, name}
|
|
|
|
}
|
2017-11-29 04:09:37 +00:00
|
|
|
return nil, errdefs.System(err)
|
2015-05-13 01:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerStatPath stats the filesystem resource at the specified path in the
|
|
|
|
// container identified by the given name.
|
2015-09-29 17:51:40 +00:00
|
|
|
func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) {
|
2019-08-09 12:10:07 +00:00
|
|
|
ctr, err := daemon.GetContainer(name)
|
2015-05-13 01:21:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-09 12:10:07 +00:00
|
|
|
stat, err = daemon.containerStatPath(ctr, path)
|
2017-07-19 14:20:13 +00:00
|
|
|
if err == nil {
|
|
|
|
return stat, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, containerFileNotFound{path, name}
|
|
|
|
}
|
2017-11-29 04:09:37 +00:00
|
|
|
return nil, errdefs.System(err)
|
2015-05-13 01:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2015-09-29 17:51:40 +00:00
|
|
|
func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) {
|
2019-08-09 12:10:07 +00:00
|
|
|
ctr, err := daemon.GetContainer(name)
|
2015-05-13 01:21:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-09 12:10:07 +00:00
|
|
|
content, stat, err = daemon.containerArchivePath(ctr, path)
|
2017-07-19 14:20:13 +00:00
|
|
|
if err == nil {
|
|
|
|
return content, stat, nil
|
2017-03-15 18:29:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-19 14:20:13 +00:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, nil, containerFileNotFound{path, name}
|
|
|
|
}
|
2017-11-29 04:09:37 +00:00
|
|
|
return nil, nil, errdefs.System(err)
|
2015-05-13 01:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ContainerExtractToDir extracts the given archive to the specified location
|
|
|
|
// in the filesystem of the container identified by the given name. The given
|
|
|
|
// path must be of a directory in the container. If it is not, the error will
|
2022-09-27 20:24:51 +00:00
|
|
|
// be an errdefs.InvalidParameter. If noOverwriteDirNonDir is true then it will
|
2015-05-13 01:21:26 +00:00
|
|
|
// be an error if unpacking the given content would cause an existing directory
|
|
|
|
// to be replaced with a non-directory and vice versa.
|
2016-11-14 13:37:08 +00:00
|
|
|
func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error {
|
2019-08-09 12:10:07 +00:00
|
|
|
ctr, err := daemon.GetContainer(name)
|
2015-05-13 01:21:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-08-09 12:10:07 +00:00
|
|
|
err = daemon.containerExtractToDir(ctr, path, copyUIDGID, noOverwriteDirNonDir, content)
|
2017-07-19 14:20:13 +00:00
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return containerFileNotFound{path, name}
|
|
|
|
}
|
2017-11-29 04:09:37 +00:00
|
|
|
return errdefs.System(err)
|
2015-05-13 01:21:26 +00:00
|
|
|
}
|