github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/daemon/copy.go (about)

     1  package daemon
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/docker/docker/engine"
     7  )
     8  
     9  func (daemon *Daemon) ContainerCopy(job *engine.Job) engine.Status {
    10  	if len(job.Args) != 2 {
    11  		return job.Errorf("Usage: %s CONTAINER RESOURCE\n", job.Name)
    12  	}
    13  
    14  	var (
    15  		name     = job.Args[0]
    16  		resource = job.Args[1]
    17  	)
    18  
    19  	if container := daemon.Get(name); container != nil {
    20  
    21  		data, err := container.Copy(resource)
    22  		if err != nil {
    23  			return job.Error(err)
    24  		}
    25  		defer data.Close()
    26  
    27  		if _, err := io.Copy(job.Stdout, data); err != nil {
    28  			return job.Error(err)
    29  		}
    30  		return engine.StatusOK
    31  	}
    32  	return job.Errorf("No such container: %s", name)
    33  }