forked from TrueCloudLab/restic
layout: Fix corner cases
This commit is contained in:
parent
0da7264e75
commit
f531ca3b48
3 changed files with 29 additions and 9 deletions
|
@ -14,7 +14,11 @@ var cloudLayoutPaths = defaultLayoutPaths
|
||||||
|
|
||||||
// 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 *CloudLayout) Dirname(h restic.Handle) string {
|
func (l *CloudLayout) Dirname(h restic.Handle) string {
|
||||||
return l.URL + l.Join(l.Path, "/", cloudLayoutPaths[h.Type])
|
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.
|
// Filename returns a path to a file, including its name.
|
||||||
|
|
|
@ -20,7 +20,11 @@ var s3LayoutPaths = map[restic.FileType]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 *S3Layout) Dirname(h restic.Handle) string {
|
||||||
return l.URL + l.Join(l.Path, "/", s3LayoutPaths[h.Type])
|
if h.Type == restic.ConfigFile {
|
||||||
|
return l.URL + l.Join(l.Path, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
return l.URL + l.Join(l.Path, "/", s3LayoutPaths[h.Type]) + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filename returns a path to a file, including its name.
|
// Filename returns a path to a file, including its name.
|
||||||
|
|
|
@ -152,44 +152,56 @@ func TestCloudLayoutURLs(t *testing.T) {
|
||||||
l Layout
|
l Layout
|
||||||
h restic.Handle
|
h restic.Handle
|
||||||
fn string
|
fn string
|
||||||
|
dir string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
&CloudLayout{URL: "https://hostname.foo", Path: "", Join: path.Join},
|
&CloudLayout{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/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&CloudLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join},
|
&CloudLayout{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/locks/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},
|
&CloudLayout{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/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&S3Layout{URL: "https://hostname.foo", Path: "/", Join: path.Join},
|
&S3Layout{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/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&S3Layout{URL: "https://hostname.foo:1234/prefix/repo", Path: "", Join: path.Join},
|
&S3Layout{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/",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
&S3Layout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join},
|
&S3Layout{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/",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run("cloud", func(t *testing.T) {
|
t.Run(fmt.Sprintf("%T", test.l), func(t *testing.T) {
|
||||||
res := test.l.Filename(test.h)
|
fn := test.l.Filename(test.h)
|
||||||
if res != test.fn {
|
if fn != test.fn {
|
||||||
t.Fatalf("wrong filename, want %v, got %v", test.fn, res)
|
t.Fatalf("wrong filename, want %v, got %v", test.fn, fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := test.l.Dirname(test.h)
|
||||||
|
if dir != test.dir {
|
||||||
|
t.Fatalf("wrong dirname, want %v, got %v", test.dir, dir)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue