| 1 |
//go:build freebsd |
| 2 |
// +build freebsd |
| 3 |
|
| 4 |
package fs |
| 5 |
|
| 6 |
import ( |
| 7 |
"io" |
| 8 |
"os" |
| 9 |
|
| 10 |
"github.com/pkg/errors" |
| 11 |
"golang.org/x/sys/unix" |
| 12 |
) |
| 13 |
|
| 14 |
func copyFile(source, target string) error { |
| 15 |
src, err := os.Open(source) |
| 16 |
if err != nil { |
| 17 |
return errors.Wrapf(err, "failed to open source %s", source) |
| 18 |
} |
| 19 |
defer src.Close() |
| 20 |
tgt, err := os.Create(target) |
| 21 |
if err != nil { |
| 22 |
return errors.Wrapf(err, "failed to open target %s", target) |
| 23 |
} |
| 24 |
defer tgt.Close() |
| 25 |
|
| 26 |
return copyFileContent(tgt, src) |
| 27 |
} |
| 28 |
|
| 29 |
func copyFileContent(dst, src *os.File) error { |
| 30 |
buf := bufferPool.Get().(*[]byte) |
| 31 |
_, err := io.CopyBuffer(dst, src, *buf) |
| 32 |
bufferPool.Put(buf) |
| 33 |
return err |
| 34 |
} |
| 35 |
|
| 36 |
func mknod(dst string, mode uint32, rDev int) error { |
| 37 |
return unix.Mknod(dst, uint32(mode), uint64(rDev)) |
| 38 |
} |