// Copy copies files or folders from a container.
// It is the caller's responsiblity to call Close on returned TarReader.
777192
func (client *Client) Copy(cid, resource string) (TarReader, error) {
	data, err := json.Marshal(map[string]string{"Resource": resource})
	if err != nil {
		return TarReader{}, err
	}

	uri := fmt.Sprintf("/containers/%s/copy", cid)

	resp, err := client.DoRequest("POST", uri, bytes.NewReader(data))
	if err != nil {
		return TarReader{}, err
	}
	return TarReader{
		tar.NewReader(resp.Body),
		resp.Body,
	}, nil
}
478865
func (p *PNSExecutor) CopyFile(containerID string, sourcePath string, destPath string) (err error) {
	destFile, err := os.Create(destPath)
	if err != nil {
		return err
	}
	defer func() {
		// exit chroot and close the file. preserve the original error
		deferErr := p.exitChroot()
		if err == nil && deferErr != nil {
			err = errors.InternalWrapError(deferErr)
		}
		deferErr = destFile.Close()
		if err == nil && deferErr != nil {
			err = errors.InternalWrapError(deferErr)
		}
	}()
	w := bufio.NewWriter(destFile)
	err = p.enterChroot()
	if err != nil {
		return err
	}

	err = archive.TarGzToWriter(sourcePath, w)
	if err != nil {
		return err
	}

	return nil
}
355667
func (t PackageTree) Copy() PackageTree {
	t2 := PackageTree{
		ImportRoot: t.ImportRoot,
		Packages:   map[string]PackageOrErr{},
	}

	for path, poe := range t.Packages {
		poe2 := PackageOrErr{
			Err: poe.Err,
			P:   poe.P,
		}
		if len(poe.P.Imports) > 0 {
			poe2.P.Imports = make([]string, len(poe.P.Imports))
			copy(poe2.P.Imports, poe.P.Imports)
		}
		if len(poe.P.TestImports) > 0 {
			poe2.P.TestImports = make([]string, len(poe.P.TestImports))
			copy(poe2.P.TestImports, poe.P.TestImports)
		}

		t2.Packages[path] = poe2
	}

	return t2
}
530037
func (fs *Filespace) Copy(src, dest string) error {
	return disk.Copy(fs.path+src, fs.path+dest)
}
119575
func (s *SSHRunner) Copy(f assets.CopyableFile) error {
	deleteCmd := fmt.Sprintf("sudo rm -f %s", path.Join(f.GetTargetDir(), f.GetTargetName()))
	mkdirCmd := fmt.Sprintf("sudo mkdir -p %s", f.GetTargetDir())
	for _, cmd := range []string{deleteCmd, mkdirCmd} {
		if err := s.Run(cmd); err != nil {
			return errors.Wrapf(err, "pre-copy")
		}
	}

	sess, err := s.c.NewSession()
	if err != nil {
		return errors.Wrap(err, "NewSession")
	}

	w, err := sess.StdinPipe()
	if err != nil {
		return errors.Wrap(err, "StdinPipe")
	}
	// The scpcmd below *should not* return until all data is copied and the
	// StdinPipe is closed. But let's use a WaitGroup to make it expicit.
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()
		defer w.Close()
		header := fmt.Sprintf("C%s %d %s\n", f.GetPermissions(), f.GetLength(), f.GetTargetName())
		fmt.Fprint(w, header)
		io.Copy(w, f)
		fmt.Fprint(w, "\x00")
	}()

	_, err = sess.CombinedOutput(fmt.Sprintf("sudo scp -t %s", f.GetTargetDir()))
	if err != nil {
		return err
	}
	wg.Wait()
	return nil
}
208604
func (_m *APIClient) CopyToContainer(ctx context.Context, _a1 string, path string, content io.Reader, options types.CopyToContainerOptions) error {
	ret := _m.Called(ctx, _a1, path, content, options)

	var r0 error
	if rf, ok := ret.Get(0).(func(context.Context, string, string, io.Reader, types.CopyToContainerOptions) error); ok {
		r0 = rf(ctx, _a1, path, content, options)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
174280
func (s *Scheme) Copy(src Object) (Object, error) {
	dst, err := s.DeepCopy(src)
	if err != nil {
		return nil, err
	}
	return dst.(Object), nil
}
602314
func (b *storageDBWrapper) Copy() *storageDBWrapper {
	session := b.session.Copy()

	coll := b.metaColl.With(session)
	db := coll.Database
	txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{
		Database:               db,
		ServerSideTransactions: false,
	})
	dbWrap := storageDBWrapper{
		session:   session,
		db:        db,
		metaColl:  coll,
		txnRunner: txnRunner,
		modelUUID: b.modelUUID,
	}
	return &dbWrap
}
385264
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error {
	query := url.Values{}
	query.Set("path", filepath.ToSlash(dstPath)) // Normalize the paths used in the API.
	// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
	if !options.AllowOverwriteDirWithFile {
		query.Set("noOverwriteDirNonDir", "true")
	}

	if options.CopyUIDGID {
		query.Set("copyUIDGID", "true")
	}

	apiPath := "/containers/" + containerID + "/archive"

	response, err := cli.putRaw(ctx, apiPath, query, content, nil)
	defer ensureReaderClosed(response)
	if err != nil {
		return wrapResponseError(err, response, "container:path", containerID+":"+dstPath)
	}

	// TODO this code converts non-error status-codes (e.g., "204 No Content") into an error; verify if this is the desired behavior
	if response.statusCode != http.StatusOK {
		return fmt.Errorf("unexpected status code from daemon: %d", response.statusCode)
	}

	return nil
}
883383
func (c *Container) Clone() *Container {
	vj := *c
	if vj.next != nil {
		vj.next = vj.next.Clone()
	}
	return &vj
}
1304387
func Copy(src reflect.Value) reflect.Value {
	d := make(deepcopy)
	return d.copy(src)
}
212994
func Copy(ctx context.Context, s Store, src, des Object) error {
	// for Providers that offer fast path, and use the backend copier
	if src.StorageSource() == des.StorageSource() {
		if cp, ok := s.(StoreCopy); ok {
			return cp.Copy(ctx, src, des)
		}
	}

	// Slow path, open an io.Reader from the source and copy it to an
	// io.Writer to the destination.  This is considered a "slow path" because we
	// have to act as a broker to relay bytes between the two objects.  Some
	// stores support moving data using an API call.
	fout, err := s.NewWriterWithContext(ctx, des.Name(), src.MetaData())
	if err != nil {
		gou.Warnf("Move could not open destination %v", src.Name())
		return err
	}
	fin, err := s.NewReaderWithContext(ctx, src.Name())
	if err != nil {
		gou.Warnf("Move could not open source %v err=%v", src.Name(), err)
		return err
	}
	if _, err = io.Copy(fout, fin); err != nil {
		return err
	}
	if err := fin.Close(); err != nil {
		return err
	}
	if err := fout.Close(); err != nil { //this will flush and sync the file.
		return err
	}
	return nil
}
1037558
func (v *Vault) Copy() *Vault {
	if v == nil {
		return nil
	}

	nv := new(Vault)
	*nv = *v
	return nv
}
1255420
func (fp *fieldPath) copy() *fieldPath {
	x := fpPool.Get().(*fieldPath)
	copy(x.path, fp.path)
	x.last = fp.last
	x.done = fp.done
	return x
}
984018
func (s *Node) Copy() *Node {
	localCopy := deepcopy.Copy(*s)
	nodeCopy := localCopy.(Node)
	return &nodeCopy
}
349419
func (r *Reader) copy(b []byte) (n int) {
	n += copy(b, r.buf)
	if len(r.buf) >= n {
		// If there's still some buffered data left, truncate the buffer
		// and return.
		r.buf = r.buf[n:]
	}

	if len(r.buf) == 0 {
		r.done()
	}

	return
}
356695
func Copy(src, dest string) error {
	fsrc, err := os.Open(src)
	if err != nil {
		return err
	}
	defer fsrc.Close()

	fdest, err := os.Create(dest)
	if err != nil {
		return err
	}
	defer fdest.Close()

	if _, err := io.Copy(fdest, fsrc); err != nil {
		return err
	}

	return nil
}