mirror of
https://github.com/restic/restic.git
synced 2026-08-14 09:33:18 +00:00
Return helpful error if subfolder syntax fails on Windows (#21813)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user