1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-21 23:33:03 +00:00

Move PreallocateFile to fs package

This commit is contained in:
DRON-666 2021-02-02 17:43:40 +03:00
parent 88c63a029c
commit ffc6b3d887
5 changed files with 11 additions and 11 deletions

View file

@ -1,4 +1,4 @@
package restorer
package fs
import (
"os"
@ -6,7 +6,7 @@ import (
"golang.org/x/sys/unix"
)
func preallocateFile(wr *os.File, size int64) error {
func PreallocateFile(wr *os.File, size int64) error {
// try contiguous first
fst := unix.Fstore_t{
Flags: unix.F_ALLOCATECONTIG | unix.F_ALLOCATEALL,

View file

@ -1,4 +1,4 @@
package restorer
package fs
import (
"os"
@ -6,7 +6,7 @@ import (
"golang.org/x/sys/unix"
)
func preallocateFile(wr *os.File, size int64) error {
func PreallocateFile(wr *os.File, size int64) error {
if size <= 0 {
return nil
}

View file

@ -1,11 +1,11 @@
//go:build !linux && !darwin
// +build !linux,!darwin
package restorer
package fs
import "os"
func preallocateFile(wr *os.File, size int64) error {
func PreallocateFile(wr *os.File, size int64) error {
// Maybe truncate can help?
// Windows: This calls SetEndOfFile which preallocates space on disk
return wr.Truncate(size)

View file

@ -1,4 +1,4 @@
package restorer
package fs
import (
"os"
@ -7,7 +7,6 @@ import (
"syscall"
"testing"
"github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/test"
)
@ -23,7 +22,7 @@ func TestPreallocate(t *testing.T) {
test.OK(t, wr.Close())
}()
err = preallocateFile(wr, i)
err = PreallocateFile(wr, i)
if err == syscall.ENOTSUP {
t.SkipNow()
}
@ -32,7 +31,7 @@ func TestPreallocate(t *testing.T) {
fi, err := wr.Stat()
test.OK(t, err)
efi := fs.ExtendedStat(fi)
efi := ExtendedStat(fi)
test.Assert(t, efi.Size == i || efi.Blocks > 0, "Preallocated size of %v, got size %v block %v", i, efi.Size, efi.Blocks)
})
}

View file

@ -6,6 +6,7 @@ import (
"github.com/cespare/xxhash/v2"
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/fs"
)
// writes blobs to target files.
@ -72,7 +73,7 @@ func (w *filesWriter) writeToFile(path string, blob []byte, offset int64, create
return nil, err
}
} else {
err := preallocateFile(wr.File, createSize)
err := fs.PreallocateFile(wr.File, createSize)
if err != nil {
// Just log the preallocate error but don't let it cause the restore process to fail.
// Preallocate might return an error if the filesystem (implementation) does not