mirror of
https://github.com/restic/restic.git
synced 2026-09-27 06:20:30 +00:00
Use array instead of hash for backend.ID
Since backend.ID is always a slice of constant length, use an array
instead of a slice. Mostly, arrays behave as slices, except that an
array cannot be nil, so use `*backend.ID` insteaf of `backend.ID` in
places where the absence of an ID is possible (e.g. for the Subtree of a
Node, which may not present when the node is a file node).
This change allows to directly use backend.ID as the the key for a map,
so that arbitrary data structures (e.g. a Set implemented as a
map[backend.ID]struct{}) can easily be formed.
This commit is contained in:
+13
-13
@@ -13,17 +13,17 @@ import (
|
||||
)
|
||||
|
||||
type Snapshot struct {
|
||||
Time time.Time `json:"time"`
|
||||
Parent backend.ID `json:"parent,omitempty"`
|
||||
Tree backend.ID `json:"tree"`
|
||||
Paths []string `json:"paths"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
UID uint32 `json:"uid,omitempty"`
|
||||
GID uint32 `json:"gid,omitempty"`
|
||||
Excludes []string `json:"excludes,omitempty"`
|
||||
Time time.Time `json:"time"`
|
||||
Parent *backend.ID `json:"parent,omitempty"`
|
||||
Tree *backend.ID `json:"tree"`
|
||||
Paths []string `json:"paths"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
UID uint32 `json:"uid,omitempty"`
|
||||
GID uint32 `json:"gid,omitempty"`
|
||||
Excludes []string `json:"excludes,omitempty"`
|
||||
|
||||
id backend.ID // plaintext ID, used during restore
|
||||
id *backend.ID // plaintext ID, used during restore
|
||||
}
|
||||
|
||||
func NewSnapshot(paths []string) (*Snapshot, error) {
|
||||
@@ -52,7 +52,7 @@ func NewSnapshot(paths []string) (*Snapshot, error) {
|
||||
}
|
||||
|
||||
func LoadSnapshot(repo *repository.Repository, id backend.ID) (*Snapshot, error) {
|
||||
sn := &Snapshot{id: id}
|
||||
sn := &Snapshot{id: &id}
|
||||
err := repo.LoadJSONUnpacked(backend.Snapshot, id, sn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -65,7 +65,7 @@ func (sn Snapshot) String() string {
|
||||
return fmt.Sprintf("<Snapshot of %v at %s>", sn.Paths, sn.Time)
|
||||
}
|
||||
|
||||
func (sn Snapshot) ID() backend.ID {
|
||||
func (sn Snapshot) ID() *backend.ID {
|
||||
return sn.id
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func FindSnapshot(repo *repository.Repository, s string) (backend.ID, error) {
|
||||
// find snapshot id with prefix
|
||||
name, err := backend.Find(repo.Backend(), backend.Snapshot, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return backend.ID{}, err
|
||||
}
|
||||
|
||||
return backend.ParseID(name)
|
||||
|
||||
Reference in New Issue
Block a user