Merge branch 'btrfs-clone' of https://github.com/bozaro/git-lfs into bozaro-btrfs-clone

This commit is contained in:
risk danger olson 2016-02-04 12:53:24 -07:00
commit d884dadd94
3 changed files with 52 additions and 0 deletions

@ -45,6 +45,12 @@ func (w *CallbackReader) Read(p []byte) (int, error) {
}
func CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb CopyCallback) (int64, error) {
if success, _ := CloneFile(writer, reader); success {
if cb != nil {
cb(totalSize, totalSize, 0)
}
return totalSize, nil
}
if cb == nil {
return io.Copy(writer, reader)
}

11
lfs/util_generic.go Normal file

@ -0,0 +1,11 @@
// +build !linux !cgo
package lfs
import (
"io"
)
func CloneFile(writer io.Writer, reader io.Reader) (bool, error) {
return false, nil
}

35
lfs/util_linux.go Normal file

@ -0,0 +1,35 @@
// +build linux,cgo
package lfs
/*
#include <sys/ioctl.h>
#undef BTRFS_IOCTL_MAGIC
#define BTRFS_IOCTL_MAGIC 0x94
#undef BTRFS_IOC_CLONE
#define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int)
*/
import "C"
import (
"os"
"io"
"syscall"
)
const (
BtrfsIocClone = C.BTRFS_IOC_CLONE
)
func CloneFile(writer io.Writer, reader io.Reader) (bool, error) {
fdst, fdstFound := writer.(*os.File)
fsrc, fsrcFound := reader.(*os.File)
if fdstFound && fsrcFound {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fdst.Fd(), BtrfsIocClone, fsrc.Fd()); err != 0 {
return false, err
}
return true, nil
}
return false, nil
}