mirror of https://github.com/restic/restic.git
Move PreallocateFile to fs package
This commit is contained in:
parent
88c63a029c
commit
ffc6b3d887
|
@ -1,4 +1,4 @@
|
||||||
package restorer
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func preallocateFile(wr *os.File, size int64) error {
|
func PreallocateFile(wr *os.File, size int64) error {
|
||||||
// try contiguous first
|
// try contiguous first
|
||||||
fst := unix.Fstore_t{
|
fst := unix.Fstore_t{
|
||||||
Flags: unix.F_ALLOCATECONTIG | unix.F_ALLOCATEALL,
|
Flags: unix.F_ALLOCATECONTIG | unix.F_ALLOCATEALL,
|
|
@ -1,4 +1,4 @@
|
||||||
package restorer
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func preallocateFile(wr *os.File, size int64) error {
|
func PreallocateFile(wr *os.File, size int64) error {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
//go:build !linux && !darwin
|
//go:build !linux && !darwin
|
||||||
// +build !linux,!darwin
|
// +build !linux,!darwin
|
||||||
|
|
||||||
package restorer
|
package fs
|
||||||
|
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
func preallocateFile(wr *os.File, size int64) error {
|
func PreallocateFile(wr *os.File, size int64) error {
|
||||||
// Maybe truncate can help?
|
// Maybe truncate can help?
|
||||||
// Windows: This calls SetEndOfFile which preallocates space on disk
|
// Windows: This calls SetEndOfFile which preallocates space on disk
|
||||||
return wr.Truncate(size)
|
return wr.Truncate(size)
|
|
@ -1,4 +1,4 @@
|
||||||
package restorer
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
@ -7,7 +7,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/fs"
|
|
||||||
"github.com/restic/restic/internal/test"
|
"github.com/restic/restic/internal/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ func TestPreallocate(t *testing.T) {
|
||||||
test.OK(t, wr.Close())
|
test.OK(t, wr.Close())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = preallocateFile(wr, i)
|
err = PreallocateFile(wr, i)
|
||||||
if err == syscall.ENOTSUP {
|
if err == syscall.ENOTSUP {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
|
@ -32,7 +31,7 @@ func TestPreallocate(t *testing.T) {
|
||||||
fi, err := wr.Stat()
|
fi, err := wr.Stat()
|
||||||
test.OK(t, err)
|
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)
|
test.Assert(t, efi.Size == i || efi.Blocks > 0, "Preallocated size of %v, got size %v block %v", i, efi.Size, efi.Blocks)
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/cespare/xxhash/v2"
|
"github.com/cespare/xxhash/v2"
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
|
"github.com/restic/restic/internal/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// writes blobs to target files.
|
// writes blobs to target files.
|
||||||
|
@ -72,7 +73,7 @@ func (w *filesWriter) writeToFile(path string, blob []byte, offset int64, create
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := preallocateFile(wr.File, createSize)
|
err := fs.PreallocateFile(wr.File, createSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Just log the preallocate error but don't let it cause the restore process to fail.
|
// 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
|
// Preallocate might return an error if the filesystem (implementation) does not
|
||||||
|
|
Loading…
Reference in New Issue