-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfile.go
63 lines (52 loc) · 1.18 KB
/
file.go
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
63
package restic
import (
"fmt"
"github.com/rubiojr/rapi/internal/errors"
)
// FileType is the type of a file in the backend.
type FileType string
// These are the different data types a backend can store.
const (
PackFile FileType = "data" // use data, as packs are stored under /data in repo
KeyFile FileType = "key"
LockFile FileType = "lock"
SnapshotFile FileType = "snapshot"
IndexFile FileType = "index"
ConfigFile FileType = "config"
)
// Handle is used to store and access data in a backend.
type Handle struct {
Type FileType
ContainedBlobType BlobType
Name string
}
func (h Handle) String() string {
name := h.Name
if len(name) > 10 {
name = name[:10]
}
return fmt.Sprintf("<%s/%s>", h.Type, name)
}
// Valid returns an error if h is not valid.
func (h Handle) Valid() error {
if h.Type == "" {
return errors.New("type is empty")
}
switch h.Type {
case PackFile:
case KeyFile:
case LockFile:
case SnapshotFile:
case IndexFile:
case ConfigFile:
default:
return errors.Errorf("invalid Type %q", h.Type)
}
if h.Type == ConfigFile {
return nil
}
if h.Name == "" {
return errors.New("invalid Name")
}
return nil
}