// Copy copies the PackageTree.
//
// This is really only useful as a defensive measure to prevent external state
// mutations.
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
}
902011
func (p *DataFrame) Copy() *DataFrame {
	result := NewDataFrame()

	for k, v := range p.data {
		result.data[k] = v
	}

	result.parent = p

	return result
}
1171390
func (c *Client) copy(ctx context.Context, version string) error {
	backupDir := path.Join(path.Dir(c.Path), "backup")
	if _, err := os.Stat(backupDir); os.IsNotExist(err) {
		if err = os.Mkdir(backupDir, 0700); err != nil {
			return err
		}
	} else if err != nil {
		return err
	}

	fromFile, err := os.Open(c.Path)
	if err != nil {
		return err
	}
	defer fromFile.Close()

	toName := fmt.Sprintf("%s.%s", path.Base(c.Path), version)
	toPath := path.Join(backupDir, toName)
	toFile, err := os.OpenFile(toPath, os.O_RDWR|os.O_CREATE, 0600)
	if err != nil {
		return err
	}
	defer toFile.Close()

	_, err = io.Copy(toFile, fromFile)
	if err != nil {
		return err
	}

	c.logger.Info("Successfully created ", toPath)

	return nil
}
976651
func (p *Package) Copy(name string, r io.Reader) {
	if p.err != nil {
		return
	}

	zf, err := p.z.Create(name)
	if err != nil {
		p.err = err
		return
	}

	checksum, err := copyAndChecksum(zf, r)
	if err != nil {
		p.err = err
		return
	}

	p.manifest[name] = checksum
}
386847
func (sc *SetComprehension) Copy() *SetComprehension {
	cpy := *sc
	cpy.Body = sc.Body.Copy()
	cpy.Term = sc.Term.Copy()
	return &cpy
}
1186087
func Copy(w Sender, r Receiver) (int, error) {
	if senderTo, ok := r.(SenderTo); ok {
		if n, err := senderTo.SendTo(w); err != ErrIncompatibleSender {
			return n, err
		}
	}
	if receiverFrom, ok := w.(ReceiverFrom); ok {
		if n, err := receiverFrom.ReceiveFrom(r); err != ErrIncompatibleReceiver {
			return n, err
		}
	}

	var n int
	for {
		var m interface{}
		err := r.Receive(&m)
		if err != nil {
			if err == io.EOF {
				break
			} else {
				return n, err
			}
		}

		err = w.Send(m)
		if err != nil {
			return n, err
		}
		n++
	}
	return n, nil
}
37445
func Copy(ctx context.Context, src, dst string) (err error) {
	// Check context
	if err = ctx.Err(); err != nil {
		return
	}

	// Stat src
	var statSrc os.FileInfo
	if statSrc, err = os.Stat(src); err != nil {
		err = errors.Wrapf(err, "stating %s failed", src)
		return
	}

	// Check context
	if err = ctx.Err(); err != nil {
		return
	}

	// Dir
	if statSrc.IsDir() {
		if err = filepath.Walk(src, func(path string, info os.FileInfo, errWalk error) (err error) {
			// Check error
			if errWalk != nil {
				err = errWalk
				return
			}

			// Do not process root
			if src == path {
				return
			}

			// Copy
			var p = filepath.Join(dst, strings.TrimPrefix(path, filepath.Clean(src)))
			if err = Copy(ctx, path, p); err != nil {
				err = errors.Wrapf(err, "copying %s to %s failed", path, p)
				return
			}
			return nil
		}); err != nil {
			return
		}
		return
	}

	// Open the source file
	var srcFile *os.File
	if srcFile, err = os.Open(src); err != nil {
		err = errors.Wrapf(err, "opening %s failed", src)
		return
	}
	defer srcFile.Close()

	// Create the destination folder
	if err = os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
		err = errors.Wrapf(err, "mkdirall %s failed", filepath.Dir(dst))
		return
	}

	// Check context
	if err = ctx.Err(); err != nil {
		return
	}

	// Create the destination file
	var dstFile *os.File
	if dstFile, err = os.Create(dst); err != nil {
		err = errors.Wrapf(err, "creating %s failed", dst)
		return
	}
	defer dstFile.Close()

	// Chmod using os.chmod instead of file.Chmod
	if err = os.Chmod(dst, statSrc.Mode()); err != nil {
		err = errors.Wrapf(err, "chmod %s %s failed", dst, statSrc.Mode())
		return
	}

	// Check context
	if err = ctx.Err(); err != nil {
		return
	}

	// Copy the content
	if _, err = astiio.Copy(ctx, srcFile, dstFile); err != nil {
		err = errors.Wrapf(err, "copying content of %s to %s failed", srcFile.Name(), dstFile.Name())
		return
	}

	return
}
808729
func (n *Node) Copy(c *Node) {
	n.State = c.State
	n.Priority = c.Priority
	n.Host.Copy(&c.Host)
	n.VserversEnabled = c.VserversEnabled
}
538496
func (ac *ArrayComprehension) Copy() *ArrayComprehension {
	cpy := *ac
	cpy.Body = ac.Body.Copy()
	cpy.Term = ac.Term.Copy()
	return &cpy
}
1053635
func (n *node) copy() *node {
	return &node{
		balance:  n.balance,
		children: [2]*node{n.children[0], n.children[1]},
		entry:    n.entry,
	}
}
639666
func (r *Store) Copy(ctx context.Context, from, to string) error {
	return r.move(ctx, from, to, false)
}
1350634
func (tr Matrix) Copy() Matrix {
	var result Matrix
	copy(result[:], tr[:])
	return result
}
356565
func (e *Env) Copy() *Env {
	e.Lock()
	defer e.Unlock()
	copy := Env{
		name:     e.name,
		env:      make(map[string]reflect.Value),
		typ:      make(map[string]reflect.Type),
		parent:   e.parent,
		external: e.external,
	}
	for name, value := range e.env {
		copy.env[name] = value
	}
	for name, typ := range e.typ {
		copy.typ[name] = typ
	}
	return &copy
}
312446
func (opt Option) Copy(p []byte) Option {
	n := copy(p, opt.Name)
	opt.Name = p[:n]
	opt.Parameters, p = opt.Parameters.Copy(p[n:])
	return opt
}
1010949
func (mod *Module) Copy() *Module {
	cpy := *mod
	cpy.Rules = make([]*Rule, len(mod.Rules))
	for i := range mod.Rules {
		cpy.Rules[i] = mod.Rules[i].Copy()
	}
	cpy.Imports = make([]*Import, len(mod.Imports))
	for i := range mod.Imports {
		cpy.Imports[i] = mod.Imports[i].Copy()
	}
	cpy.Package = mod.Package.Copy()
	return &cpy
}
725642
func Copy(src []byte) (dst []byte) {
	dst = make([]byte, len(src))
	copy(dst, src)
	return
}
806450
func (that *JSONNode) Copy(other *JSONNode, deepCopy bool) *JSONNode {
	if that.t != TypeUndefined {
		panic(ErrorCopyType)
	}

	if other.t == TypeValue {
		*that = *other
	} else if other.t == TypeArray {
		if !deepCopy {
			*that = *other
		} else {
			that.Array(len(other.a))
			for i := range other.a {
				that.At(i).Copy(other.At(i), deepCopy)
			}
		}
	} else if other.t == TypeMap {
		that.SetType(other.t)
		if !deepCopy {
			for val := range other.m {
				that.m[val] = other.m[val]
			}
		} else {
			for val := range other.m {
				that.Map(val).Copy(other.At(val), deepCopy)
			}
		}
	}
	return that
}