mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
33 lines
587 B
Go
33 lines
587 B
Go
|
// +build freebsd
|
||
|
|
||
|
package fs
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"os"
|
||
|
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
func copyFile(source, target string) error {
|
||
|
src, err := os.Open(source)
|
||
|
if err != nil {
|
||
|
return errors.Wrapf(err, "failed to open source %s", source)
|
||
|
}
|
||
|
defer src.Close()
|
||
|
tgt, err := os.Create(target)
|
||
|
if err != nil {
|
||
|
return errors.Wrapf(err, "failed to open target %s", target)
|
||
|
}
|
||
|
defer tgt.Close()
|
||
|
|
||
|
return copyFileContent(tgt, src)
|
||
|
}
|
||
|
|
||
|
func copyFileContent(dst, src *os.File) error {
|
||
|
buf := bufferPool.Get().(*[]byte)
|
||
|
_, err := io.CopyBuffer(dst, src, *buf)
|
||
|
bufferPool.Put(buf)
|
||
|
return err
|
||
|
}
|