From c37d587f81f27bd1c4588fe4526684b36f7a90cf Mon Sep 17 00:00:00 2001 From: DRON-666 <64691982+DRON-666@users.noreply.github.com> Date: Tue, 2 Feb 2021 17:44:40 +0300 Subject: [PATCH] Use PreallocateFile in local backend --- internal/backend/local/local.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/backend/local/local.go b/internal/backend/local/local.go index be332e8ad..d6bdef1e4 100644 --- a/internal/backend/local/local.go +++ b/internal/backend/local/local.go @@ -148,6 +148,13 @@ func (b *Local) Save(_ context.Context, h restic.Handle, rd restic.RewindReader) } }(f) + // preallocate disk space + if size := rd.Length(); size > 0 { + if err := fs.PreallocateFile(f, size); err != nil { + debug.Log("Failed to preallocate %v with size %v: %v", finalname, size, err) + } + } + // save data, then sync wbytes, err := io.Copy(f, rd) if err != nil {