mirror of
https://github.com/octoleo/restic.git
synced 2024-11-23 13:17:42 +00:00
fs: retry preallocate on Linux if interrupted by signal
This commit is contained in:
parent
4f0affd4f7
commit
34fe73ea42
@ -2,6 +2,7 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@ -12,5 +13,17 @@ func PreallocateFile(wr *os.File, size int64) error {
|
|||||||
}
|
}
|
||||||
// int fallocate(int fd, int mode, off_t offset, off_t len)
|
// int fallocate(int fd, int mode, off_t offset, off_t len)
|
||||||
// use mode = 0 to also change the file size
|
// use mode = 0 to also change the file size
|
||||||
return unix.Fallocate(int(wr.Fd()), 0, 0, size)
|
return ignoringEINTR(func() error { return unix.Fallocate(int(wr.Fd()), 0, 0, size) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignoringEINTR makes a function call and repeats it if it returns
|
||||||
|
// an EINTR error.
|
||||||
|
// copied from /usr/lib/go/src/internal/poll/fd_posix.go of go 1.23.1
|
||||||
|
func ignoringEINTR(fn func() error) error {
|
||||||
|
for {
|
||||||
|
err := fn()
|
||||||
|
if err != syscall.EINTR {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user