mirror of
https://github.com/rclone/rclone
synced 2024-12-28 21:03:45 +01:00
local: preallocate files on linux with fallocate(2)
This commit is contained in:
parent
f29c6049fc
commit
9fa8c959ee
@ -1,4 +1,4 @@
|
||||
//+build !windows
|
||||
//+build !windows,!linux
|
||||
|
||||
package local
|
||||
|
||||
|
22
backend/local/preallocate_unix.go
Normal file
22
backend/local/preallocate_unix.go
Normal file
@ -0,0 +1,22 @@
|
||||
//+build linux
|
||||
|
||||
package local
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// preAllocate the file for performance reasons
|
||||
func preAllocate(size int64, out *os.File) error {
|
||||
if size <= 0 {
|
||||
return nil
|
||||
}
|
||||
err := unix.Fallocate(int(out.Fd()), unix.FALLOC_FL_KEEP_SIZE, 0, size)
|
||||
// FIXME could be doing something here
|
||||
// if err == unix.ENOSPC {
|
||||
// log.Printf("No space")
|
||||
// }
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user