mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
backup: store but warn if extended metadata for item is incomplete
Files were not included in the backup if the extended metadata for the file could not be read. This is rather drastic. Instead settle on returning a warning but still including the file in the backup.
This commit is contained in:
@@ -3,6 +3,7 @@ package archiver
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -2338,3 +2339,28 @@ func TestRacyFileSwap(t *testing.T) {
|
||||
t.Errorf("Save() excluded the node, that's unexpected")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetadataBackupErrorFiltering(t *testing.T) {
|
||||
tempdir := t.TempDir()
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
filename := filepath.Join(tempdir, "file")
|
||||
rtest.OK(t, os.WriteFile(filename, []byte("example"), 0o600))
|
||||
fi, err := os.Stat(filename)
|
||||
rtest.OK(t, err)
|
||||
|
||||
arch := New(repo, fs.Local{}, Options{})
|
||||
|
||||
var filteredErr error
|
||||
replacementErr := fmt.Errorf("replacement")
|
||||
arch.Error = func(item string, err error) error {
|
||||
filteredErr = err
|
||||
return replacementErr
|
||||
}
|
||||
|
||||
// check that errors from reading extended metadata are properly filtered
|
||||
node, err := arch.nodeFromFileInfo("file", filename+"invalid", fi, false)
|
||||
rtest.Assert(t, node != nil, "node is missing")
|
||||
rtest.Assert(t, err == replacementErr, "expected %v got %v", replacementErr, err)
|
||||
rtest.Assert(t, filteredErr != nil, "missing inner error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user