diff --git a/src/restic/backend/layout.go b/src/restic/backend/layout.go index 1fa110760..38990e044 100644 --- a/src/restic/backend/layout.go +++ b/src/restic/backend/layout.go @@ -128,19 +128,19 @@ func DetectLayout(repo Filesystem, dir string) (Layout, error) { repo = &LocalFilesystem{} } - // key file in the "keys" dir (DefaultLayout or CloudLayout) + // key file in the "keys" dir (DefaultLayout) foundKeysFile, err := hasBackendFile(repo, repo.Join(dir, defaultLayoutPaths[restic.KeyFile])) if err != nil { return nil, err } - // key file in the "key" dir (S3Layout) + // key file in the "key" dir (S3LegacyLayout) foundKeyFile, err := hasBackendFile(repo, repo.Join(dir, s3LayoutPaths[restic.KeyFile])) if err != nil { return nil, err } - // data file in "data" directory (S3Layout or CloudLayout) + // data file in "data" directory (S3LegacyLayout) foundDataFile, err := hasBackendFile(repo, repo.Join(dir, s3LayoutPaths[restic.DataFile])) if err != nil { return nil, err @@ -152,14 +152,6 @@ func DetectLayout(repo Filesystem, dir string) (Layout, error) { return nil, err } - if foundKeysFile && foundDataFile && !foundKeyFile && !foundDataSubdirFile { - debug.Log("found cloud layout at %v", dir) - return &CloudLayout{ - Path: dir, - Join: repo.Join, - }, nil - } - if foundKeysFile && foundDataSubdirFile && !foundKeyFile && !foundDataFile { debug.Log("found default layout at %v", dir) return &DefaultLayout{ @@ -190,11 +182,6 @@ func ParseLayout(repo Filesystem, layout, defaultLayout, path string) (l Layout, Path: path, Join: repo.Join, } - case "cloud": - l = &CloudLayout{ - Path: path, - Join: repo.Join, - } case "s3legacy": l = &S3LegacyLayout{ Path: path, @@ -214,7 +201,7 @@ func ParseLayout(repo Filesystem, layout, defaultLayout, path string) (l Layout, } debug.Log("layout detected: %v", l) default: - return nil, errors.Errorf("unknown backend layout string %q, may be one of: default, cloud, s3legacy", layout) + return nil, errors.Errorf("unknown backend layout string %q, may be one of: default, s3legacy", layout) } return l, nil diff --git a/src/restic/backend/layout_cloud.go b/src/restic/backend/layout_cloud.go deleted file mode 100644 index 6331d4709..000000000 --- a/src/restic/backend/layout_cloud.go +++ /dev/null @@ -1,46 +0,0 @@ -package backend - -import "restic" - -// CloudLayout implements the default layout for cloud storage backends, as -// described in the Design document. -type CloudLayout struct { - URL string - Path string - Join func(...string) string -} - -var cloudLayoutPaths = defaultLayoutPaths - -// Dirname returns the directory path for a given file type and name. -func (l *CloudLayout) Dirname(h restic.Handle) string { - if h.Type == restic.ConfigFile { - return l.URL + l.Join(l.Path, "/") - } - - return l.URL + l.Join(l.Path, "/", cloudLayoutPaths[h.Type]) + "/" -} - -// Filename returns a path to a file, including its name. -func (l *CloudLayout) Filename(h restic.Handle) string { - name := h.Name - - if h.Type == restic.ConfigFile { - name = "config" - } - - return l.URL + l.Join(l.Path, "/", cloudLayoutPaths[h.Type], name) -} - -// Paths returns all directory names -func (l *CloudLayout) Paths() (dirs []string) { - for _, p := range cloudLayoutPaths { - dirs = append(dirs, l.URL+l.Join(l.Path, p)) - } - return dirs -} - -// Basedir returns the base dir name for files of type t. -func (l *CloudLayout) Basedir(t restic.FileType) string { - return l.URL + l.Join(l.Path, cloudLayoutPaths[t]) -} diff --git a/src/restic/backend/layout_rest.go b/src/restic/backend/layout_rest.go new file mode 100644 index 000000000..2d01ece79 --- /dev/null +++ b/src/restic/backend/layout_rest.go @@ -0,0 +1,45 @@ +package backend + +import "restic" + +// RESTLayout implements the default layout for the REST protocol. +type RESTLayout struct { + URL string + Path string + Join func(...string) string +} + +var restLayoutPaths = defaultLayoutPaths + +// Dirname returns the directory path for a given file type and name. +func (l *RESTLayout) Dirname(h restic.Handle) string { + if h.Type == restic.ConfigFile { + return l.URL + l.Join(l.Path, "/") + } + + return l.URL + l.Join(l.Path, "/", restLayoutPaths[h.Type]) + "/" +} + +// Filename returns a path to a file, including its name. +func (l *RESTLayout) Filename(h restic.Handle) string { + name := h.Name + + if h.Type == restic.ConfigFile { + name = "config" + } + + return l.URL + l.Join(l.Path, "/", restLayoutPaths[h.Type], name) +} + +// Paths returns all directory names +func (l *RESTLayout) Paths() (dirs []string) { + for _, p := range restLayoutPaths { + dirs = append(dirs, l.URL+l.Join(l.Path, p)) + } + return dirs +} + +// Basedir returns the base dir name for files of type t. +func (l *RESTLayout) Basedir(t restic.FileType) string { + return l.URL + l.Join(l.Path, restLayoutPaths[t]) +} diff --git a/src/restic/backend/layout_test.go b/src/restic/backend/layout_test.go index 4c296f29e..11e33ca98 100644 --- a/src/restic/backend/layout_test.go +++ b/src/restic/backend/layout_test.go @@ -79,7 +79,7 @@ func TestDefaultLayout(t *testing.T) { } } -func TestCloudLayout(t *testing.T) { +func TestRESTLayout(t *testing.T) { path, cleanup := TempDir(t) defer cleanup() @@ -113,7 +113,7 @@ func TestCloudLayout(t *testing.T) { }, } - l := &CloudLayout{ + l := &RESTLayout{ Path: path, Join: filepath.Join, } @@ -147,7 +147,7 @@ func TestCloudLayout(t *testing.T) { } } -func TestCloudLayoutURLs(t *testing.T) { +func TestRESTLayoutURLs(t *testing.T) { var tests = []struct { l Layout h restic.Handle @@ -155,19 +155,19 @@ func TestCloudLayoutURLs(t *testing.T) { dir string }{ { - &CloudLayout{URL: "https://hostname.foo", Path: "", Join: path.Join}, + &RESTLayout{URL: "https://hostname.foo", Path: "", Join: path.Join}, restic.Handle{Type: restic.DataFile, Name: "foobar"}, "https://hostname.foo/data/foobar", "https://hostname.foo/data/", }, { - &CloudLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join}, + &RESTLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join}, restic.Handle{Type: restic.LockFile, Name: "foobar"}, "https://hostname.foo:1234/prefix/repo/locks/foobar", "https://hostname.foo:1234/prefix/repo/locks/", }, { - &CloudLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join}, + &RESTLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join}, restic.Handle{Type: restic.ConfigFile, Name: "foobar"}, "https://hostname.foo:1234/prefix/repo/config", "https://hostname.foo:1234/prefix/repo/", @@ -302,7 +302,6 @@ func TestDetectLayout(t *testing.T) { want string }{ {"repo-layout-local.tar.gz", "*backend.DefaultLayout"}, - {"repo-layout-cloud.tar.gz", "*backend.CloudLayout"}, {"repo-layout-s3-old.tar.gz", "*backend.S3LegacyLayout"}, } @@ -342,12 +341,11 @@ func TestParseLayout(t *testing.T) { want string }{ {"default", "", "*backend.DefaultLayout"}, - {"cloud", "", "*backend.CloudLayout"}, {"s3legacy", "", "*backend.S3LegacyLayout"}, - {"", "", "*backend.CloudLayout"}, + {"", "", "*backend.DefaultLayout"}, } - SetupTarTestFixture(t, path, filepath.Join("testdata", "repo-layout-cloud.tar.gz")) + SetupTarTestFixture(t, path, filepath.Join("testdata", "repo-layout-local.tar.gz")) for _, test := range tests { t.Run(test.layoutName, func(t *testing.T) { diff --git a/src/restic/backend/local/layout_test.go b/src/restic/backend/local/layout_test.go index da0b0bfc8..c5b9427a8 100644 --- a/src/restic/backend/local/layout_test.go +++ b/src/restic/backend/local/layout_test.go @@ -22,11 +22,6 @@ func TestLayout(t *testing.T) { "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false, "c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false, }}, - {"repo-layout-cloud.tar.gz", "", false, map[string]bool{ - "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false, - "c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false, - "aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false, - }}, {"repo-layout-s3-old.tar.gz", "", false, map[string]bool{ "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false, "c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false, diff --git a/src/restic/backend/rest/rest.go b/src/restic/backend/rest/rest.go index 5a0e6226b..db1118077 100644 --- a/src/restic/backend/rest/rest.go +++ b/src/restic/backend/rest/rest.go @@ -48,7 +48,7 @@ func Open(cfg Config) (restic.Backend, error) { url: cfg.URL, connChan: connChan, client: client, - Layout: &backend.CloudLayout{URL: url, Join: path.Join}, + Layout: &backend.RESTLayout{URL: url, Join: path.Join}, } return be, nil diff --git a/src/restic/backend/sftp/layout_test.go b/src/restic/backend/sftp/layout_test.go index 856bd5ce4..196dcdeba 100644 --- a/src/restic/backend/sftp/layout_test.go +++ b/src/restic/backend/sftp/layout_test.go @@ -28,11 +28,6 @@ func TestLayout(t *testing.T) { "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false, "c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false, }}, - {"repo-layout-cloud.tar.gz", "", false, map[string]bool{ - "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false, - "c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false, - "aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false, - }}, {"repo-layout-s3-old.tar.gz", "", false, map[string]bool{ "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false, "c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false, diff --git a/src/restic/backend/testdata/repo-layout-cloud.tar.gz b/src/restic/backend/testdata/repo-layout-cloud.tar.gz deleted file mode 100644 index 189832589..000000000 Binary files a/src/restic/backend/testdata/repo-layout-cloud.tar.gz and /dev/null differ