mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -05:00
* feat(snapshots): support restoring sparse files This commit implements basic support for restoring sparse files from a snapshot. When specifying "--mode=sparse" in a snapshot restore command, Kopia will make a best effort to make sure the underlying filesystem allocates the minimum amount of blocks needed to persist restored files. In other words, enabling this feature will "force" all restored files to be sparse-blocks of zero bytes in the source file should not be allocated. * Address review comments - Separate sparse option into its own bool flag - Implement sparsefile packagewith copySparse method - Truncate once before writing sparse file - Check error from Truncate - Add unit test for copySparse - Invoke GetBlockSize once per file copy - Remove support for Windows and explain why - Add unit test for stat package Co-authored-by: Dave Smith-Uchida <dave@kasten.io>
45 lines
748 B
Go
45 lines
748 B
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
package stat
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetBlockSize(t *testing.T) {
|
|
s, err := GetBlockSize(os.DevNull)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if s <= 0 {
|
|
t.Fatalf("invalid disk block size: %d, must be greater than 0", s)
|
|
}
|
|
}
|
|
|
|
func TestGetFileAllocSize(t *testing.T) {
|
|
const size = 4096
|
|
|
|
d := t.TempDir()
|
|
f := filepath.Join(d, "test")
|
|
data := bytes.Repeat([]byte{1}, size)
|
|
|
|
err := os.WriteFile(f, data, os.ModePerm)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
s, err := GetFileAllocSize(f)
|
|
if err != nil {
|
|
t.Fatalf("error getting file alloc size for %s: %v", f, err)
|
|
}
|
|
|
|
if s < size {
|
|
t.Fatalf("invalid allocated file size %d, expected at least %d", s, size)
|
|
}
|
|
}
|