github.com/moby/docker@v26.1.3+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  // ContainerStatPath stats the filesystem resource at the specified path in the
    12  // container identified by the given name.
    13  func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) {
    14  	ctr, err := daemon.GetContainer(name)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	stat, err = daemon.containerStatPath(ctr, path)
    20  	if err == nil {
    21  		return stat, nil
    22  	}
    23  
    24  	if os.IsNotExist(err) {
    25  		return nil, containerFileNotFound{path, name}
    26  	}
    27  	return nil, errdefs.System(err)
    28  }
    29  
    30  // ContainerArchivePath creates an archive of the filesystem resource at the
    31  // specified path in the container identified by the given name. Returns a
    32  // tar archive of the resource and whether it was a directory or a single file.
    33  func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) {
    34  	ctr, err := daemon.GetContainer(name)
    35  	if err != nil {
    36  		return nil, nil, err
    37  	}
    38  
    39  	content, stat, err = daemon.containerArchivePath(ctr, path)
    40  	if err == nil {
    41  		return content, stat, nil
    42  	}
    43  
    44  	if os.IsNotExist(err) {
    45  		return nil, nil, containerFileNotFound{path, name}
    46  	}
    47  	return nil, nil, errdefs.System(err)
    48  }
    49  
    50  // ContainerExtractToDir extracts the given archive to the specified location
    51  // in the filesystem of the container identified by the given name. The given
    52  // path must be of a directory in the container. If it is not, the error will
    53  // be an errdefs.InvalidParameter. If noOverwriteDirNonDir is true then it will
    54  // be an error if unpacking the given content would cause an existing directory
    55  // to be replaced with a non-directory and vice versa.
    56  func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error {
    57  	ctr, err := daemon.GetContainer(name)
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	err = daemon.containerExtractToDir(ctr, path, copyUIDGID, noOverwriteDirNonDir, content)
    63  	if err == nil {
    64  		return nil
    65  	}
    66  
    67  	if os.IsNotExist(err) {
    68  		return containerFileNotFound{path, name}
    69  	}
    70  	return errdefs.System(err)
    71  }