mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 07:29:35 +01:00
local: factor PreAllocate and SetSparse to lib/file
This commit is contained in:
parent
1f50b70919
commit
36d2c46bcf
@ -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
|
||||
err = preAllocate(src.Size(), f)
|
||||
err = file.PreAllocate(src.Size(), f)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
// Pre-allocate the file for performance reasons
|
||||
err = preAllocate(size, out)
|
||||
err = file.PreAllocate(size, out)
|
||||
if err != nil {
|
||||
fs.Debugf(o, "Failed to pre-allocate: %v", err)
|
||||
}
|
||||
// Set the file to be a sparse file (important on Windows)
|
||||
err = setSparse(out)
|
||||
err = file.SetSparse(out)
|
||||
if err != nil {
|
||||
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
|
||||
|
||||
package local
|
||||
package file
|
||||
|
||||
import (
|
||||
"os"
|
||||
@ -18,8 +18,8 @@ var (
|
||||
fallocFlagsIndex int32
|
||||
)
|
||||
|
||||
// preAllocate the file for performance reasons
|
||||
func preAllocate(size int64, out *os.File) error {
|
||||
// PreAllocate the file for performance reasons
|
||||
func PreAllocate(size int64, out *os.File) error {
|
||||
if size <= 0 {
|
||||
return nil
|
||||
}
|
||||
@ -45,7 +45,7 @@ again:
|
||||
return err
|
||||
}
|
||||
|
||||
// setSparse makes the file be a sparse file
|
||||
func setSparse(out *os.File) error {
|
||||
// SetSparse makes the file be a sparse file
|
||||
func SetSparse(out *os.File) error {
|
||||
return nil
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//+build windows
|
||||
|
||||
package local
|
||||
package file
|
||||
|
||||
import (
|
||||
"os"
|
||||
@ -32,8 +32,8 @@ type ioStatusBlock struct {
|
||||
Status, Information uintptr
|
||||
}
|
||||
|
||||
// preAllocate the file for performance reasons
|
||||
func preAllocate(size int64, out *os.File) error {
|
||||
// PreAllocate the file for performance reasons
|
||||
func PreAllocate(size int64, out *os.File) error {
|
||||
if size <= 0 {
|
||||
return nil
|
||||
}
|
||||
@ -82,8 +82,8 @@ const (
|
||||
FSCTL_SET_SPARSE = 0x000900c4
|
||||
)
|
||||
|
||||
// setSparse makes the file be a sparse file
|
||||
func setSparse(out *os.File) error {
|
||||
// SetSparse makes the file be a sparse file
|
||||
func SetSparse(out *os.File) error {
|
||||
err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, nil, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DeviceIoControl FSCTL_SET_SPARSE")
|
Loading…
Reference in New Issue
Block a user