forked from TrueCloudLab/rclone
local: factor PreAllocate and SetSparse to lib/file
This commit is contained in:
parent
1f50b70919
commit
36d2c46bcf
5 changed files with 28 additions and 28 deletions
|
@ -977,7 +977,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Pre-allocate the file for performance reasons
|
// Pre-allocate the file for performance reasons
|
||||||
err = preAllocate(src.Size(), f)
|
err = file.PreAllocate(src.Size(), f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(o, "Failed to pre-allocate: %v", err)
|
fs.Debugf(o, "Failed to pre-allocate: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -1064,12 +1064,12 @@ func (f *Fs) OpenWriterAt(ctx context.Context, remote string, size int64) (fs.Wr
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Pre-allocate the file for performance reasons
|
// Pre-allocate the file for performance reasons
|
||||||
err = preAllocate(size, out)
|
err = file.PreAllocate(size, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(o, "Failed to pre-allocate: %v", err)
|
fs.Debugf(o, "Failed to pre-allocate: %v", err)
|
||||||
}
|
}
|
||||||
// Set the file to be a sparse file (important on Windows)
|
// Set the file to be a sparse file (important on Windows)
|
||||||
err = setSparse(out)
|
err = file.SetSparse(out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(o, "Failed to set sparse: %v", err)
|
fs.Debugf(o, "Failed to set sparse: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
//+build !windows,!linux
|
|
||||||
|
|
||||||
package local
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
// preAllocate the file for performance reasons
|
|
||||||
func preAllocate(size int64, out *os.File) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// setSparse makes the file be a sparse file
|
|
||||||
func setSparse(out *os.File) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
15
lib/file/preallocate_other.go
Normal file
15
lib/file/preallocate_other.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
//+build !windows,!linux
|
||||||
|
|
||||||
|
package file
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
// PreAllocate the file for performance reasons
|
||||||
|
func PreAllocate(size int64, out *os.File) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSparse makes the file be a sparse file
|
||||||
|
func SetSparse(out *os.File) error {
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
//+build linux
|
//+build linux
|
||||||
|
|
||||||
package local
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -18,8 +18,8 @@ var (
|
||||||
fallocFlagsIndex int32
|
fallocFlagsIndex int32
|
||||||
)
|
)
|
||||||
|
|
||||||
// preAllocate the file for performance reasons
|
// PreAllocate the file for performance reasons
|
||||||
func preAllocate(size int64, out *os.File) error {
|
func PreAllocate(size int64, out *os.File) error {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ again:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// setSparse makes the file be a sparse file
|
// SetSparse makes the file be a sparse file
|
||||||
func setSparse(out *os.File) error {
|
func SetSparse(out *os.File) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
//+build windows
|
//+build windows
|
||||||
|
|
||||||
package local
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -32,8 +32,8 @@ type ioStatusBlock struct {
|
||||||
Status, Information uintptr
|
Status, Information uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
// preAllocate the file for performance reasons
|
// PreAllocate the file for performance reasons
|
||||||
func preAllocate(size int64, out *os.File) error {
|
func PreAllocate(size int64, out *os.File) error {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ const (
|
||||||
FSCTL_SET_SPARSE = 0x000900c4
|
FSCTL_SET_SPARSE = 0x000900c4
|
||||||
)
|
)
|
||||||
|
|
||||||
// setSparse makes the file be a sparse file
|
// SetSparse makes the file be a sparse file
|
||||||
func setSparse(out *os.File) error {
|
func SetSparse(out *os.File) error {
|
||||||
err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, nil, nil)
|
err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "DeviceIoControl FSCTL_SET_SPARSE")
|
return errors.Wrap(err, "DeviceIoControl FSCTL_SET_SPARSE")
|
Loading…
Reference in a new issue