From a9be9867828b65d1b8ac6c21c9d695b0ee294ec2 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 29 Jul 2024 21:11:47 +0200 Subject: [PATCH] restorer: add minimal long path handling test --- internal/restorer/restorer_test.go | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 9c02afe68..191f3b8ef 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -1506,3 +1506,36 @@ func TestRestoreToFile(t *testing.T) { err := res.RestoreTo(ctx, tempdir) rtest.Assert(t, strings.Contains(err.Error(), "cannot create target directory"), "unexpected error %v", err) } + +func TestRestorerLongPath(t *testing.T) { + tmp := t.TempDir() + + longPath := tmp + for i := 0; i < 20; i++ { + longPath = filepath.Join(longPath, "aaaaaaaaaaaaaaaaaaaa") + } + + rtest.OK(t, os.MkdirAll(longPath, 0o700)) + f, err := fs.OpenFile(filepath.Join(longPath, "file"), fs.O_CREATE|fs.O_RDWR, 0o600) + rtest.OK(t, err) + _, err = f.WriteString("Hello, World!") + rtest.OK(t, err) + rtest.OK(t, f.Close()) + + repo := repository.TestRepository(t) + + local := &fs.Local{} + sc := archiver.NewScanner(local) + rtest.OK(t, sc.Scan(context.TODO(), []string{tmp})) + arch := archiver.New(repo, local, archiver.Options{}) + sn, _, _, err := arch.Snapshot(context.Background(), []string{tmp}, archiver.SnapshotOptions{}) + rtest.OK(t, err) + + res := NewRestorer(repo, sn, Options{}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + rtest.OK(t, res.RestoreTo(ctx, tmp)) + _, err = res.VerifyFiles(ctx, tmp) + rtest.OK(t, err) +}