File: layout_rest.go

package info (click to toggle)
restic 0.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,824 kB
  • sloc: sh: 3,704; makefile: 50; python: 34
file content (62 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package layout

import (
	"path"

	"github.com/restic/restic/internal/backend"
)

// RESTLayout implements the default layout for the REST protocol.
type RESTLayout struct {
	url string
}

var restLayoutPaths = defaultLayoutPaths

func NewRESTLayout(url string) *RESTLayout {
	return &RESTLayout{
		url: url,
	}
}

func (l *RESTLayout) String() string {
	return "<RESTLayout>"
}

// Name returns the name for this layout.
func (l *RESTLayout) Name() string {
	return "rest"
}

// 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 + "/"
	}

	return l.url + path.Join("/", restLayoutPaths[h.Type]) + "/"
}

// Filename returns a path to a file, including its name.
func (l *RESTLayout) Filename(h backend.Handle) string {
	name := h.Name

	if h.Type == backend.ConfigFile {
		name = "config"
	}

	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+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 + path.Join("/", restLayoutPaths[t]), false
}