Rename layout s3 -> s3legacy

This commit is contained in:
Alexander Neumann 2017-05-15 21:58:03 +02:00
parent a4e3a0dd97
commit 61cade6222
4 changed files with 22 additions and 22 deletions

View file

@ -170,7 +170,7 @@ func DetectLayout(repo Filesystem, dir string) (Layout, error) {
if foundKeyFile && foundDataFile && !foundKeysFile && !foundDataSubdirFile { if foundKeyFile && foundDataFile && !foundKeysFile && !foundDataSubdirFile {
debug.Log("found s3 layout at %v", dir) debug.Log("found s3 layout at %v", dir)
return &S3Layout{ return &S3LegacyLayout{
Path: dir, Path: dir,
Join: repo.Join, Join: repo.Join,
}, nil }, nil
@ -195,8 +195,8 @@ func ParseLayout(repo Filesystem, layout, defaultLayout, path string) (l Layout,
Path: path, Path: path,
Join: repo.Join, Join: repo.Join,
} }
case "s3": case "s3legacy":
l = &S3Layout{ l = &S3LegacyLayout{
Path: path, Path: path,
Join: repo.Join, Join: repo.Join,
} }
@ -214,7 +214,7 @@ func ParseLayout(repo Filesystem, layout, defaultLayout, path string) (l Layout,
} }
debug.Log("layout detected: %v", l) debug.Log("layout detected: %v", l)
default: default:
return nil, errors.Errorf("unknown backend layout string %q, may be one of: default, cloud, s3", layout) return nil, errors.Errorf("unknown backend layout string %q, may be one of: default, cloud, s3legacy", layout)
} }
return l, nil return l, nil

View file

@ -2,9 +2,9 @@ package backend
import "restic" import "restic"
// S3Layout implements the old layout used for s3 cloud storage backends, as // S3LegacyLayout implements the old layout used for s3 cloud storage backends, as
// described in the Design document. // described in the Design document.
type S3Layout struct { type S3LegacyLayout struct {
URL string URL string
Path string Path string
Join func(...string) string Join func(...string) string
@ -19,7 +19,7 @@ var s3LayoutPaths = map[restic.FileType]string{
} }
// join calls Join with the first empty elements removed. // join calls Join with the first empty elements removed.
func (l *S3Layout) join(url string, items ...string) string { func (l *S3LegacyLayout) join(url string, items ...string) string {
for len(items) > 0 && items[0] == "" { for len(items) > 0 && items[0] == "" {
items = items[1:] items = items[1:]
} }
@ -35,7 +35,7 @@ func (l *S3Layout) join(url string, items ...string) string {
} }
// Dirname returns the directory path for a given file type and name. // Dirname returns the directory path for a given file type and name.
func (l *S3Layout) Dirname(h restic.Handle) string { func (l *S3LegacyLayout) Dirname(h restic.Handle) string {
if h.Type == restic.ConfigFile { if h.Type == restic.ConfigFile {
return l.URL + l.Join(l.Path, "/") return l.URL + l.Join(l.Path, "/")
} }
@ -44,7 +44,7 @@ func (l *S3Layout) Dirname(h restic.Handle) string {
} }
// Filename returns a path to a file, including its name. // Filename returns a path to a file, including its name.
func (l *S3Layout) Filename(h restic.Handle) string { func (l *S3LegacyLayout) Filename(h restic.Handle) string {
name := h.Name name := h.Name
if h.Type == restic.ConfigFile { if h.Type == restic.ConfigFile {
@ -55,7 +55,7 @@ func (l *S3Layout) Filename(h restic.Handle) string {
} }
// Paths returns all directory names // Paths returns all directory names
func (l *S3Layout) Paths() (dirs []string) { func (l *S3LegacyLayout) Paths() (dirs []string) {
for _, p := range s3LayoutPaths { for _, p := range s3LayoutPaths {
dirs = append(dirs, l.Join(l.Path, p)) dirs = append(dirs, l.Join(l.Path, p))
} }
@ -63,6 +63,6 @@ func (l *S3Layout) Paths() (dirs []string) {
} }
// Basedir returns the base dir name for type t. // Basedir returns the base dir name for type t.
func (l *S3Layout) Basedir(t restic.FileType) string { func (l *S3LegacyLayout) Basedir(t restic.FileType) string {
return l.Join(l.Path, s3LayoutPaths[t]) return l.Join(l.Path, s3LayoutPaths[t])
} }

View file

@ -173,37 +173,37 @@ func TestCloudLayoutURLs(t *testing.T) {
"https://hostname.foo:1234/prefix/repo/", "https://hostname.foo:1234/prefix/repo/",
}, },
{ {
&S3Layout{URL: "https://hostname.foo", Path: "/", Join: path.Join}, &S3LegacyLayout{URL: "https://hostname.foo", Path: "/", Join: path.Join},
restic.Handle{Type: restic.DataFile, Name: "foobar"}, restic.Handle{Type: restic.DataFile, Name: "foobar"},
"https://hostname.foo/data/foobar", "https://hostname.foo/data/foobar",
"https://hostname.foo/data/", "https://hostname.foo/data/",
}, },
{ {
&S3Layout{URL: "https://hostname.foo:1234/prefix/repo", Path: "", Join: path.Join}, &S3LegacyLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "", Join: path.Join},
restic.Handle{Type: restic.LockFile, Name: "foobar"}, restic.Handle{Type: restic.LockFile, Name: "foobar"},
"https://hostname.foo:1234/prefix/repo/lock/foobar", "https://hostname.foo:1234/prefix/repo/lock/foobar",
"https://hostname.foo:1234/prefix/repo/lock/", "https://hostname.foo:1234/prefix/repo/lock/",
}, },
{ {
&S3Layout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join}, &S3LegacyLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join},
restic.Handle{Type: restic.ConfigFile, Name: "foobar"}, restic.Handle{Type: restic.ConfigFile, Name: "foobar"},
"https://hostname.foo:1234/prefix/repo/config", "https://hostname.foo:1234/prefix/repo/config",
"https://hostname.foo:1234/prefix/repo/", "https://hostname.foo:1234/prefix/repo/",
}, },
{ {
&S3Layout{URL: "", Path: "", Join: path.Join}, &S3LegacyLayout{URL: "", Path: "", Join: path.Join},
restic.Handle{Type: restic.DataFile, Name: "foobar"}, restic.Handle{Type: restic.DataFile, Name: "foobar"},
"data/foobar", "data/foobar",
"data/", "data/",
}, },
{ {
&S3Layout{URL: "", Path: "", Join: path.Join}, &S3LegacyLayout{URL: "", Path: "", Join: path.Join},
restic.Handle{Type: restic.LockFile, Name: "foobar"}, restic.Handle{Type: restic.LockFile, Name: "foobar"},
"lock/foobar", "lock/foobar",
"lock/", "lock/",
}, },
{ {
&S3Layout{URL: "", Path: "/", Join: path.Join}, &S3LegacyLayout{URL: "", Path: "/", Join: path.Join},
restic.Handle{Type: restic.ConfigFile, Name: "foobar"}, restic.Handle{Type: restic.ConfigFile, Name: "foobar"},
"/config", "/config",
"/", "/",
@ -225,7 +225,7 @@ func TestCloudLayoutURLs(t *testing.T) {
} }
} }
func TestS3Layout(t *testing.T) { func TestS3LegacyLayout(t *testing.T) {
path, cleanup := TempDir(t) path, cleanup := TempDir(t)
defer cleanup() defer cleanup()
@ -259,7 +259,7 @@ func TestS3Layout(t *testing.T) {
}, },
} }
l := &S3Layout{ l := &S3LegacyLayout{
Path: path, Path: path,
Join: filepath.Join, Join: filepath.Join,
} }
@ -303,7 +303,7 @@ func TestDetectLayout(t *testing.T) {
}{ }{
{"repo-layout-local.tar.gz", "*backend.DefaultLayout"}, {"repo-layout-local.tar.gz", "*backend.DefaultLayout"},
{"repo-layout-cloud.tar.gz", "*backend.CloudLayout"}, {"repo-layout-cloud.tar.gz", "*backend.CloudLayout"},
{"repo-layout-s3-old.tar.gz", "*backend.S3Layout"}, {"repo-layout-s3-old.tar.gz", "*backend.S3LegacyLayout"},
} }
var fs = &LocalFilesystem{} var fs = &LocalFilesystem{}
@ -343,7 +343,7 @@ func TestParseLayout(t *testing.T) {
}{ }{
{"default", "", "*backend.DefaultLayout"}, {"default", "", "*backend.DefaultLayout"},
{"cloud", "", "*backend.CloudLayout"}, {"cloud", "", "*backend.CloudLayout"},
{"s3", "", "*backend.S3Layout"}, {"s3legacy", "", "*backend.S3LegacyLayout"},
{"", "", "*backend.CloudLayout"}, {"", "", "*backend.CloudLayout"},
} }

View file

@ -45,7 +45,7 @@ func Open(cfg Config) (restic.Backend, error) {
bucketname: cfg.Bucket, bucketname: cfg.Bucket,
prefix: cfg.Prefix, prefix: cfg.Prefix,
cacheObjSize: make(map[string]int64), cacheObjSize: make(map[string]int64),
Layout: &backend.S3Layout{Path: cfg.Prefix, Join: path.Join}, Layout: &backend.S3LegacyLayout{Path: cfg.Prefix, Join: path.Join},
} }
client.SetCustomTransport(backend.Transport()) client.SetCustomTransport(backend.Transport())