2022-10-15 14:23:39 +00:00
|
|
|
package layout
|
2017-05-15 20:01:49 +00:00
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
import (
|
2024-08-26 19:15:58 +00:00
|
|
|
"path"
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
"github.com/restic/restic/internal/backend"
|
|
|
|
)
|
2017-05-15 20:01:49 +00:00
|
|
|
|
|
|
|
// RESTLayout implements the default layout for the REST protocol.
|
|
|
|
type RESTLayout struct {
|
2024-08-26 19:15:58 +00:00
|
|
|
url string
|
2017-05-15 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var restLayoutPaths = defaultLayoutPaths
|
|
|
|
|
2024-08-26 19:15:58 +00:00
|
|
|
func NewRESTLayout(url string) *RESTLayout {
|
|
|
|
return &RESTLayout{
|
|
|
|
url: url,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:59:41 +00:00
|
|
|
func (l *RESTLayout) String() string {
|
|
|
|
return "<RESTLayout>"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the name for this layout.
|
|
|
|
func (l *RESTLayout) Name() string {
|
|
|
|
return "rest"
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:01:49 +00:00
|
|
|
// Dirname returns the directory path for a given file type and name.
|
2023-10-01 09:40:12 +00:00
|
|
|
func (l *RESTLayout) Dirname(h backend.Handle) string {
|
|
|
|
if h.Type == backend.ConfigFile {
|
2024-08-26 19:15:58 +00:00
|
|
|
return l.url + "/"
|
2017-05-15 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
2024-08-26 19:15:58 +00:00
|
|
|
return l.url + path.Join("/", restLayoutPaths[h.Type]) + "/"
|
2017-05-15 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filename returns a path to a file, including its name.
|
2023-10-01 09:40:12 +00:00
|
|
|
func (l *RESTLayout) Filename(h backend.Handle) string {
|
2017-05-15 20:01:49 +00:00
|
|
|
name := h.Name
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
if h.Type == backend.ConfigFile {
|
2017-05-15 20:01:49 +00:00
|
|
|
name = "config"
|
|
|
|
}
|
|
|
|
|
2024-08-26 19:15:58 +00:00
|
|
|
return l.url + path.Join("/", restLayoutPaths[h.Type], name)
|
2017-05-15 20:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paths returns all directory names
|
|
|
|
func (l *RESTLayout) Paths() (dirs []string) {
|
|
|
|
for _, p := range restLayoutPaths {
|
2024-08-26 19:15:58 +00:00
|
|
|
dirs = append(dirs, l.url+path.Join("/", p))
|
2017-05-15 20:01:49 +00:00
|
|
|
}
|
|
|
|
return dirs
|
|
|
|
}
|
|
|
|
|
|
|
|
// Basedir returns the base dir name for files of type t.
|
2023-10-01 09:40:12 +00:00
|
|
|
func (l *RESTLayout) Basedir(t backend.FileType) (dirname string, subdirs bool) {
|
2024-08-26 19:15:58 +00:00
|
|
|
return l.url + path.Join("/", restLayoutPaths[t]), false
|
2017-05-15 20:01:49 +00:00
|
|
|
}
|