mirror of
https://github.com/restic/restic.git
synced 2026-09-12 07:27:56 +00:00
backup: skip source paths that cannot be accessed (#21852)
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
@@ -76,6 +77,28 @@ func TestCollectTargets(t *testing.T) {
|
||||
rtest.Assert(t, err == ErrInvalidSourceData, "expected error when not all targets exist")
|
||||
}
|
||||
|
||||
func TestFilterExistingUnreadable(t *testing.T) {
|
||||
dir := rtest.TempDir(t)
|
||||
|
||||
existing := filepath.Join(dir, "existing")
|
||||
rtest.OK(t, os.Mkdir(existing, 0755))
|
||||
|
||||
file := filepath.Join(dir, "file")
|
||||
rtest.OK(t, os.WriteFile(file, []byte("x"), 0600))
|
||||
|
||||
// Regression test for #5667. A target whose Lstat fails with an error other
|
||||
// than ErrNotExist must be skipped (ENOTDIR on unix, NUL byte everywhere).
|
||||
for _, unreadable := range []string{filepath.Join(file, "child"), "invalid\x00path"} {
|
||||
result, err := filterExisting([]string{unreadable}, t.Logf)
|
||||
rtest.Assert(t, errors.Is(err, ErrNoSourceData), "input %q: expected ErrNoSourceData; got %v", unreadable, err)
|
||||
rtest.Assert(t, len(result) == 0, "input %q: expected no targets; got %v", unreadable, result)
|
||||
|
||||
result, err = filterExisting([]string{existing, unreadable}, t.Logf)
|
||||
rtest.Assert(t, errors.Is(err, ErrInvalidSourceData), "input %q: expected ErrInvalidSourceData; got %v", unreadable, err)
|
||||
rtest.Equals(t, []string{existing}, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadFilenamesRaw(t *testing.T) {
|
||||
// These should all be returned exactly as-is.
|
||||
expected := []string{
|
||||
|
||||
Reference in New Issue
Block a user