Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions lfs/util_generic.go
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions lfs/util_linux.go
Original file line number Diff line number Diff line change
@@ -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
}