diff --git a/src/restic/backend/layout.go b/src/restic/backend/layout.go index cff77e25a..a6087c502 100644 --- a/src/restic/backend/layout.go +++ b/src/restic/backend/layout.go @@ -6,6 +6,7 @@ import ( "path/filepath" "regexp" "restic" + "restic/debug" "restic/errors" "restic/fs" ) @@ -140,28 +141,36 @@ func DetectLayout(repo Filesystem, dir string) (Layout, error) { } if foundKeysFile && foundDataFile && !foundKeyFile && !foundDataSubdirFile { - return &CloudLayout{}, nil + debug.Log("found cloud layout at %v", dir) + return &CloudLayout{ + Path: dir, + Join: repo.Join, + }, nil } if foundKeysFile && foundDataSubdirFile && !foundKeyFile && !foundDataFile { - return &DefaultLayout{}, nil + debug.Log("found default layout at %v", dir) + return &DefaultLayout{ + Path: dir, + Join: repo.Join, + }, nil } if foundKeyFile && foundDataFile && !foundKeysFile && !foundDataSubdirFile { - return &S3Layout{}, nil + debug.Log("found s3 layout at %v", dir) + return &S3Layout{ + Path: dir, + Join: repo.Join, + }, nil } return nil, errors.New("auto-detecting the filesystem layout failed") } // ParseLayout parses the config string and returns a Layout. When layout is -// the empty string, DetectLayout is used. If repo is nil, an instance of LocalFilesystem -// is used. +// the empty string, DetectLayout is used. func ParseLayout(repo Filesystem, layout, path string) (l Layout, err error) { - if repo == nil { - repo = &LocalFilesystem{} - } - + debug.Log("parse layout string %q for backend at %v", layout, path) switch layout { case "default": l = &DefaultLayout{ diff --git a/src/restic/backend/layout_test.go b/src/restic/backend/layout_test.go index 3fe9dcf6e..e336f8178 100644 --- a/src/restic/backend/layout_test.go +++ b/src/restic/backend/layout_test.go @@ -271,7 +271,7 @@ func TestParseLayout(t *testing.T) { for _, test := range tests { t.Run(test.layoutName, func(t *testing.T) { - layout, err := ParseLayout(nil, test.layoutName, filepath.Join(path, "repo")) + layout, err := ParseLayout(&LocalFilesystem{}, test.layoutName, filepath.Join(path, "repo")) if err != nil { t.Fatal(err) } @@ -280,6 +280,11 @@ func TestParseLayout(t *testing.T) { t.Fatal("wanted some layout, but detect returned nil") } + // test that the functions work (and don't panic) + _ = layout.Dirname(restic.Handle{Type: restic.DataFile}) + _ = layout.Filename(restic.Handle{Type: restic.DataFile, Name: "1234"}) + _ = layout.Paths() + layoutName := fmt.Sprintf("%T", layout) if layoutName != test.want { t.Fatalf("want layout %v, got %v", test.want, layoutName)