mirror of
https://github.com/restic/restic.git
synced 2025-12-12 08:31:51 +00:00
data: split node and snapshot code from restic package
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/archiver"
|
||||
"github.com/restic/restic/internal/data"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/fs"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
@@ -75,11 +76,11 @@ func saveFile(t testing.TB, repo restic.BlobSaver, data string) restic.ID {
|
||||
return id
|
||||
}
|
||||
|
||||
func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode uint64, getGenericAttributes func(attr *FileAttributes, isDir bool) (genericAttributes map[restic.GenericAttributeType]json.RawMessage)) restic.ID {
|
||||
func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode uint64, getGenericAttributes func(attr *FileAttributes, isDir bool) (genericAttributes map[data.GenericAttributeType]json.RawMessage)) restic.ID {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
tree := &restic.Tree{}
|
||||
tree := &data.Tree{}
|
||||
for name, n := range nodes {
|
||||
inode++
|
||||
switch node := n.(type) {
|
||||
@@ -107,8 +108,8 @@ func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode u
|
||||
if mode == 0 {
|
||||
mode = 0644
|
||||
}
|
||||
err := tree.Insert(&restic.Node{
|
||||
Type: restic.NodeTypeFile,
|
||||
err := tree.Insert(&data.Node{
|
||||
Type: data.NodeTypeFile,
|
||||
Mode: mode,
|
||||
ModTime: node.ModTime,
|
||||
Name: name,
|
||||
@@ -122,8 +123,8 @@ func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode u
|
||||
})
|
||||
rtest.OK(t, err)
|
||||
case Symlink:
|
||||
err := tree.Insert(&restic.Node{
|
||||
Type: restic.NodeTypeSymlink,
|
||||
err := tree.Insert(&data.Node{
|
||||
Type: data.NodeTypeSymlink,
|
||||
Mode: os.ModeSymlink | 0o777,
|
||||
ModTime: node.ModTime,
|
||||
Name: name,
|
||||
@@ -142,8 +143,8 @@ func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode u
|
||||
mode = 0755
|
||||
}
|
||||
|
||||
err := tree.Insert(&restic.Node{
|
||||
Type: restic.NodeTypeDir,
|
||||
err := tree.Insert(&data.Node{
|
||||
Type: data.NodeTypeDir,
|
||||
Mode: mode,
|
||||
ModTime: node.ModTime,
|
||||
Name: name,
|
||||
@@ -158,7 +159,7 @@ func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode u
|
||||
}
|
||||
}
|
||||
|
||||
id, err := restic.SaveTree(ctx, repo, tree)
|
||||
id, err := data.SaveTree(ctx, repo, tree)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -166,7 +167,7 @@ func saveDir(t testing.TB, repo restic.BlobSaver, nodes map[string]Node, inode u
|
||||
return id
|
||||
}
|
||||
|
||||
func saveSnapshot(t testing.TB, repo restic.Repository, snapshot Snapshot, getGenericAttributes func(attr *FileAttributes, isDir bool) (genericAttributes map[restic.GenericAttributeType]json.RawMessage)) (*restic.Snapshot, restic.ID) {
|
||||
func saveSnapshot(t testing.TB, repo restic.Repository, snapshot Snapshot, getGenericAttributes func(attr *FileAttributes, isDir bool) (genericAttributes map[data.GenericAttributeType]json.RawMessage)) (*data.Snapshot, restic.ID) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
@@ -178,13 +179,13 @@ func saveSnapshot(t testing.TB, repo restic.Repository, snapshot Snapshot, getGe
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sn, err := restic.NewSnapshot([]string{"test"}, nil, "", time.Now())
|
||||
sn, err := data.NewSnapshot([]string{"test"}, nil, "", time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sn.Tree = &treeID
|
||||
id, err := restic.SaveSnapshot(ctx, repo, sn)
|
||||
id, err := data.SaveSnapshot(ctx, repo, sn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -192,7 +193,7 @@ func saveSnapshot(t testing.TB, repo restic.Repository, snapshot Snapshot, getGe
|
||||
return sn, id
|
||||
}
|
||||
|
||||
var noopGetGenericAttributes = func(attr *FileAttributes, isDir bool) (genericAttributes map[restic.GenericAttributeType]json.RawMessage) {
|
||||
var noopGetGenericAttributes = func(attr *FileAttributes, isDir bool) (genericAttributes map[data.GenericAttributeType]json.RawMessage) {
|
||||
// No-op
|
||||
return nil
|
||||
}
|
||||
@@ -553,8 +554,8 @@ func checkVisitOrder(list []TreeVisit) TraverseTreeCheck {
|
||||
var pos int
|
||||
|
||||
return func(t testing.TB) treeVisitor {
|
||||
check := func(funcName string) func(*restic.Node, string, string, []string) error {
|
||||
return func(node *restic.Node, target, location string, expectedFilenames []string) error {
|
||||
check := func(funcName string) func(*data.Node, string, string, []string) error {
|
||||
return func(node *data.Node, target, location string, expectedFilenames []string) error {
|
||||
if pos >= len(list) {
|
||||
t.Errorf("step %v, %v(%v): expected no more than %d function calls", pos, funcName, location, len(list))
|
||||
pos++
|
||||
@@ -580,9 +581,9 @@ func checkVisitOrder(list []TreeVisit) TraverseTreeCheck {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
checkNoFilename := func(funcName string) func(*restic.Node, string, string) error {
|
||||
checkNoFilename := func(funcName string) func(*data.Node, string, string) error {
|
||||
f := check(funcName)
|
||||
return func(node *restic.Node, target, location string) error {
|
||||
return func(node *data.Node, target, location string) error {
|
||||
return f(node, target, location, nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user