mirror of
https://github.com/restic/restic.git
synced 2025-08-21 04:37:34 +00:00
Enable sparseness only conditionally
We can either preallocate storage for a file or sparsify it. This detects a pack file as sparse if it contains an all zero block or consists of only one block. As the file sparsification is just an approximation, hide it behind a `--sparse` parameter.
This commit is contained in:
@@ -36,7 +36,7 @@ func TestRestorerRestoreEmptyHardlinkedFileds(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
res, err := NewRestorer(context.TODO(), repo, id)
|
||||
res, err := NewRestorer(context.TODO(), repo, id, false)
|
||||
rtest.OK(t, err)
|
||||
|
||||
res.SelectFilter = func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
||||
@@ -85,8 +85,9 @@ func TestRestorerSparseFiles(t *testing.T) {
|
||||
arch := archiver.New(repo, target, archiver.Options{})
|
||||
_, id, err := arch.Snapshot(context.Background(), []string{"/zeros"},
|
||||
archiver.SnapshotOptions{})
|
||||
rtest.OK(t, err)
|
||||
|
||||
res, err := NewRestorer(repo, id)
|
||||
res, err := NewRestorer(context.TODO(), repo, id, true)
|
||||
rtest.OK(t, err)
|
||||
|
||||
tempdir, cleanup := rtest.TempDir(t)
|
||||
@@ -102,6 +103,7 @@ func TestRestorerSparseFiles(t *testing.T) {
|
||||
content, err := ioutil.ReadFile(filename)
|
||||
rtest.OK(t, err)
|
||||
|
||||
rtest.Equals(t, len(zeros[:]), len(content))
|
||||
rtest.Equals(t, zeros[:], content)
|
||||
|
||||
fi, err := os.Stat(filename)
|
||||
|
Reference in New Issue
Block a user