// Copy a file or folder to a different location.
345467
func (c *Files) Copy(in *CopyInput) (out *CopyOutput, err error) {
	body, err := c.call("/files/copy", in)
	if err != nil {
		return
	}
	defer body.Close()

	err = json.NewDecoder(body).Decode(&out)
	return
}
1224049
func (c *Client) CopyToLocal(src string, dst string) error {
	remote, err := c.Open(src)
	if err != nil {
		return err
	}
	defer remote.Close()

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

	_, err = io.Copy(local, remote)
	return err
}
1110888
func CopyAll(dst, src string) error {
	return filepath.Walk(src, makeWalkFn(dst, src, flagDefault))
}
579648
func CopyFile(src, dst string) (err error) {
	srcStats, err := os.Stat(src)
	if err != nil {
		return
	}
	if !srcStats.Mode().IsRegular() {
		return ErrSrcNotRegularFile
	}
	dstStats, err := os.Stat(dst)
	if err != nil {
		if !os.IsNotExist(err) {
			return
		}
	} else {
		// The file already exists
		if !dstStats.Mode().IsRegular() {
			return ErrDstNotRegularFile
		}
	}
	return copyFileContents(src, dst)
}
150901
func CopyContents(dst, src string) error {
	srcF, err := os.Open(src)
	if err != nil {
		return err
	}
	defer srcF.Close()

	dstDir, _ := filepath.Split(dst)
	if dstDir != "" {
		err := os.MkdirAll(dstDir, 0755)
		if err != nil {
			return err
		}
	}

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

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

	return nil
}
121460
func Copy(srcfs, destfs filesystem.Filespace, filterFN filesystem.LoopFilter) (err error) {
	loop := fsloop.NewLoop(&fsloop.LoopData{
		Filespace: srcfs,
		DirFilter: filterFN,
		OnDir: func(fs filesystem.Filespace, subPath string) error {
			return destfs.MkdirAll(subPath, filesystem.DefaultUnixDirMode)
		},
		OnFile: func(fs filesystem.Filespace, subPath string) (err error) {
			if err = destfs.MkdirAll(path.Dir(subPath), filesystem.DefaultUnixDirMode); err != nil {
				return err
			}
			if err = StreamCopy(srcfs, destfs, subPath); err != nil {
				return err
			}
			return nil
		},
		Consumers:  1,
		Producents: 1,
	}, nil)
	loop.Run("")
	loop.Wait()
	if len(loop.Errors()) != 0 {
		return goaterr.NewErrors(loop.Errors())
	}
	return err
}
233518
func Copy(ctx context.Context, src, dst string, fn SessionFunc) (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
	}

	// 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, fn); err != nil {
				err = errors.Wrapf(err, "copying %s to %s failed", path, p)
				return

			}
			return
		}); err != nil {
			return
		}
		return
	}

	// Create ssh session
	var s *ssh.Session
	var c *astidefer.Closer
	if s, c, err = fn(); err != nil {
		err = errors.Wrap(err, "main: creating ssh session failed")
		return
	}
	defer c.Close()

	// Create the destination folder
	if err = s.Run("mkdir -p " + filepath.Dir(dst)); err != nil {
		err = errors.Wrapf(err, "astissh: creating %s failed", filepath.Dir(dst))
		return
	}

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

	// Create ssh session
	if s, c, err = fn(); err != nil {
		err = errors.Wrap(err, "main: creating ssh session failed")
		return
	}
	defer c.Close()

	// Create stdin pipe
	var stdin io.WriteCloser
	if stdin, err = s.StdinPipe(); err != nil {
		err = errors.Wrap(err, "astissh: creating stdin pipe failed")
		return
	}
	defer stdin.Close()

	// Start "scp" command
	astilog.Debugf("astissh: copying %s to %s", filepath.Base(dst), filepath.Dir(dst))
	if err = s.Start("scp -qt " + filepath.Dir(dst)); err != nil {
		err = errors.Wrapf(err, "astissh: scp to %s failed", dst)
		return
	}

	// Send metadata
	if _, err = fmt.Fprintln(stdin, fmt.Sprintf("C%04o", statSrc.Mode().Perm()), statSrc.Size(), filepath.Base(dst)); err != nil {
		err = errors.Wrapf(err, "astissh: sending metadata failed")
		return
	}

	// Copy
	if _, err = astiio.Copy(ctx, f, stdin); err != nil {
		err = errors.Wrap(err, "astissh: copying failed")
		return
	}

	// Send close
	if _, err = fmt.Fprint(stdin, "\x00"); err != nil {
		err = errors.Wrap(err, "astissh: sending close failed")
		return
	}

	// Close stdin
	stdin.Close()

	// Wait
	if err = s.Wait(); err != nil {
		err = errors.Wrap(err, "astissh: waiting failed")
		return
	}
	return
}
921117
func (c *Client) Copy(src, dst string) error {
	_, err := c.Files.Copy(&dropbox.CopyInput{
		FromPath: src,
		ToPath:   dst,
	})
	return err
}
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
}
837323
func (f *File) Copy() (*File, error) {
	var datacopy = make([]byte, len(f.data))
	copy(datacopy[:], f.data)
	return &File{
		name:     f.name,
		filemode: f.filemode,
		time:     f.time,
		data:     datacopy,
	}, nil
}
1218269
func (cm *ChanMode) Copy() *ChanMode {
	if cm == nil {
		return nil
	}
	c := *cm
	return &c
}
513491
func Copy(source, destination string) error {
	src := cleanPath(source)
	dst := cleanPath(destination)
	s, err := os.Open(src)
	if err != nil {
		return err
	}
	// no need to check errors on read only file, we already got everything
	// we need from the filesystem, so nothing can go wrong now.
	defer s.Close()

	if IsDir(src) {
		return fmt.Errorf("source path is a directory")
	}
	if IsDir(dst) {
		basename := filepath.Base(src)
		dst = path.Join(dst, basename)
	}

	d, err := os.Create(dst)
	if err != nil {
		return err
	}
	if _, err := io.Copy(d, s); err != nil {
		d.Close()
		return err
	}
	return d.Close()
}
1120530
func Copy(src, dest string) error {
	// Gather file information to set back later.
	si, err := os.Lstat(src)
	if err != nil {
		return err
	}

	// Handle symbolic link.
	if si.Mode()&os.ModeSymlink != 0 {
		target, err := os.Readlink(src)
		if err != nil {
			return err
		}
		// NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link,
		// which will lead "no such file or directory" error.
		return os.Symlink(target, dest)
	}

	sr, err := os.Open(src)
	if err != nil {
		return err
	}
	defer sr.Close()

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

	if _, err = io.Copy(dw, sr); err != nil {
		return err
	}

	// Set back file information.
	if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil {
		return err
	}
	return os.Chmod(dest, si.Mode())
}
211201
func CopyFile(dst, src string, mode os.FileMode) {
	if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
		log.Fatal(err)
	}
	destFile, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
	if err != nil {
		log.Fatal(err)
	}
	defer destFile.Close()

	srcFile, err := os.Open(src)
	if err != nil {
		log.Fatal(err)
	}
	defer srcFile.Close()

	if _, err := io.Copy(destFile, srcFile); err != nil {
		log.Fatal(err)
	}
}
791955
func copyFile(w io.Writer, file string) error {
	f, err := os.Open(file)
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = io.Copy(w, f)
	return err
}
852005
func CopyDir(dst, src string) error {
	err := os.MkdirAll(dst, 0755)
	if err != nil {
		return err
	}

	files, err := ioutil.ReadDir(src)

	for i := 0; i < len(files) && err == nil; i++ {
		file := files[i].Name()
		df := filepath.Join(dst, file)
		sf := filepath.Join(src, file)
		if IsFile(sf) {
			err = Copy(df, sf)
		} else {
			err = CopyDir(df, sf)
		}
	}

	return err
}
102044
func (env *Env) Copy(path string) error {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))
	ret := C.mdb_env_copy(env._env, cpath)
	return operrno("mdb_env_copy", ret)
}