mirror of
https://github.com/restic/restic.git
synced 2025-12-12 03:11:56 +00:00
Update snapshot summary on rewrite
Signed-off-by: Alex Johnson <hello@alex-johnson.net>
This commit is contained in:
@@ -11,6 +11,12 @@ import (
|
||||
|
||||
type NodeRewriteFunc func(node *restic.Node, path string) *restic.Node
|
||||
type FailedTreeRewriteFunc func(nodeID restic.ID, path string, err error) (restic.ID, error)
|
||||
type QueryRewrittenSizeFunc func() SnapshotSize
|
||||
|
||||
type SnapshotSize struct {
|
||||
FileCount uint
|
||||
FileSize uint64
|
||||
}
|
||||
|
||||
type RewriteOpts struct {
|
||||
// return nil to remove the node
|
||||
@@ -52,6 +58,29 @@ func NewTreeRewriter(opts RewriteOpts) *TreeRewriter {
|
||||
return rw
|
||||
}
|
||||
|
||||
func NewSnapshotSizeRewriter(rewriteNode NodeRewriteFunc) (*TreeRewriter, QueryRewrittenSizeFunc) {
|
||||
var count uint
|
||||
var size uint64
|
||||
|
||||
t := NewTreeRewriter(RewriteOpts{
|
||||
RewriteNode: func(node *restic.Node, path string) *restic.Node {
|
||||
node = rewriteNode(node, path)
|
||||
if node != nil && node.Type == "file" {
|
||||
count++
|
||||
size += node.Size
|
||||
}
|
||||
return node
|
||||
},
|
||||
DisableNodeCache: true,
|
||||
})
|
||||
|
||||
ss := func() SnapshotSize {
|
||||
return SnapshotSize{count, size}
|
||||
}
|
||||
|
||||
return t, ss
|
||||
}
|
||||
|
||||
type BlobLoadSaver interface {
|
||||
restic.BlobSaver
|
||||
restic.BlobLoader
|
||||
|
||||
Reference in New Issue
Block a user