Return helpful error if subfolder syntax fails on Windows (#21813)

This commit is contained in:
Michael Eischer
2026-05-20 22:55:01 +02:00
committed by GitHub
parent dd4f1f06a1
commit f000da3b35
9 changed files with 33 additions and 11 deletions
+4
View File
@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"runtime"
"io"
"iter"
@@ -311,6 +312,9 @@ func FindTreeDirectory(ctx context.Context, repo restic.BlobLoader, id *restic.I
return nil, fmt.Errorf("path %s: %w", subfolder, err)
}
if node == nil {
if runtime.GOOS == "windows" && strings.Contains(dir, "\\") {
return nil, fmt.Errorf("path %s: not found; subfolder syntax currently requires forward slashes; check the output of `restic ls` for valid paths", subfolder)
}
return nil, fmt.Errorf("path %s: not found", subfolder)
}
if node.Type != NodeTypeDir || node.Subtree == nil {
+17
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
@@ -401,6 +402,22 @@ func TestFindTreeDirectory(t *testing.T) {
rtest.Assert(t, err != nil, "missing error on null tree id")
}
func TestFindTreeDirectoryWindowsBackslashHint(t *testing.T) {
repo := repository.TestRepository(t)
sn := data.TestCreateSnapshot(t, repo, parseTimeUTC("2017-07-07 07:07:08"), 1)
_, err := data.FindTreeDirectory(context.TODO(), repo, sn.Tree, `missing\path`)
rtest.Assert(t, err != nil, "expected error")
if runtime.GOOS == "windows" {
rtest.Assert(t, strings.Contains(err.Error(), "forward slashes"),
"expected backslash hint on Windows, got %v", err)
} else {
rtest.Assert(t, err.Error() == `path missing\path: not found`,
"unexpected err: %v", err)
}
}
func TestDualTreeIterator(t *testing.T) {
testErr := errors.New("test error")