github.com/rawahars/moby@v24.0.4+incompatible/daemon/archive.go (about)

     1  package daemon // import "github.com/docker/docker/daemon"
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/errdefs"
     9  )
    10  
    11  // ContainerCopy performs a deprecated operation of archiving the resource at
    12  // the specified path in the container identified by the given name.
    13  func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
    14  	ctr, err := daemon.GetContainer(name)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	data, err := daemon.containerCopy(ctr, res)
    20  	if err == nil {
    21  		return data, nil
    22  	}
    23  
    24  	if os.IsNotExist(err) {
    25  		return nil, containerFileNotFound{res, name}
    26  	}
    27  	return nil, errdefs.System(err)
    28  }
    29  
    30  // ContainerStatPath stats the filesystem resource at the specified path in the
    31  // container identified by the given name.
    32  func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) {
    33  	ctr, err := daemon.GetContainer(name)
    34  	if err != nil {
    35  		return nil, err
    36  	}
    37  
    38  	stat, err = daemon.containerStatPath(ctr, path)
    39  	if err == nil {
    40  		return stat, nil
    41  	}
    42  
    43  	if os.IsNotExist(err) {
    44  		return nil, containerFileNotFound{path, name}
    45  	}
    46  	return nil, errdefs.System(err)
    47  }
    48  
    49  // ContainerArchivePath creates an archive of the filesystem resource at the
    50  // specified path in the container identified by the given name. Returns a
    51  // tar archive of the resource and whether it was a directory or a single file.
    52  func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) {
    53  	ctr, err := daemon.GetContainer(name)
    54  	if err != nil {
    55  		return nil, nil, err
    56  	}
    57  
    58  	content, stat, err = daemon.containerArchivePath(ctr, path)
    59  	if err == nil {
    60  		return content, stat, nil
    61  	}
    62  
    63  	if os.IsNotExist(err) {
    64  		return nil, nil, containerFileNotFound{path, name}
    65  	}
    66  	return nil, nil, errdefs.System(err)
    67  }
    68  
    69  // ContainerExtractToDir extracts the given archive to the specified location
    70  // in the filesystem of the container identified by the given name. The given
    71  // path must be of a directory in the container. If it is not, the error will
    72  // be an errdefs.InvalidParameter. If noOverwriteDirNonDir is true then it will
    73  // be an error if unpacking the given content would cause an existing directory
    74  // to be replaced with a non-directory and vice versa.
    75  func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error {
    76  	ctr, err := daemon.GetContainer(name)
    77  	if err != nil {
    78  		return err
    79  	}
    80  
    81  	err = daemon.containerExtractToDir(ctr, path, copyUIDGID, noOverwriteDirNonDir, content)
    82  	if err == nil {
    83  		return nil
    84  	}
    85  
    86  	if os.IsNotExist(err) {
    87  		return containerFileNotFound{path, name}
    88  	}
    89  	return errdefs.System(err)
    90  }