backend/layout: unexport fields and simplify rest layout

This commit is contained in:
Michael Eischer
2024-08-26 21:15:58 +02:00
parent 6024597028
commit af989aab4e
8 changed files with 68 additions and 78 deletions

View File

@@ -1,18 +1,24 @@
package layout
import (
"path"
"github.com/restic/restic/internal/backend"
)
// RESTLayout implements the default layout for the REST protocol.
type RESTLayout struct {
URL string
Path string
Join func(...string) string
url string
}
var restLayoutPaths = defaultLayoutPaths
func NewRESTLayout(url string) *RESTLayout {
return &RESTLayout{
url: url,
}
}
func (l *RESTLayout) String() string {
return "<RESTLayout>"
}
@@ -25,10 +31,10 @@ func (l *RESTLayout) Name() string {
// Dirname returns the directory path for a given file type and name.
func (l *RESTLayout) Dirname(h backend.Handle) string {
if h.Type == backend.ConfigFile {
return l.URL + l.Join(l.Path, "/")
return l.url + "/"
}
return l.URL + l.Join(l.Path, "/", restLayoutPaths[h.Type]) + "/"
return l.url + path.Join("/", restLayoutPaths[h.Type]) + "/"
}
// Filename returns a path to a file, including its name.
@@ -39,18 +45,18 @@ func (l *RESTLayout) Filename(h backend.Handle) string {
name = "config"
}
return l.URL + l.Join(l.Path, "/", restLayoutPaths[h.Type], name)
return l.url + path.Join("/", 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))
dirs = append(dirs, l.url+path.Join("/", p))
}
return dirs
}
// Basedir returns the base dir name for files of type t.
func (l *RESTLayout) Basedir(t backend.FileType) (dirname string, subdirs bool) {
return l.URL + l.Join(l.Path, restLayoutPaths[t]), false
return l.url + path.Join("/", restLayoutPaths[t]), false
}