aboutsummaryrefslogtreecommitdiff
path: root/repo.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-21 18:24:16 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-21 18:30:16 +0200
commit79b4564d77de71abffc82406561cc02b762c29d3 (patch)
tree0df93663d06af8457171a2fa7f67dffe006aa77c /repo.go
parentbb744d04d4bac4003072264a8696bf59ef884b16 (diff)
downloaddna-backup-79b4564d77de71abffc82406561cc02b762c29d3.tar.gz
dna-backup-79b4564d77de71abffc82406561cc02b762c29d3.zip
fix recipe diff deepequal replaces everything...
...by hydrating the chunks in loadRecipes instead of in restoreStream. Otherwise repo is not set in r.recipe chunks. Also added a generic loadDeltas for future use in loadFileLists
Diffstat (limited to 'repo.go')
-rw-r--r--repo.go32
1 files changed, 19 insertions, 13 deletions
diff --git a/repo.go b/repo.go
index ff19333..7bcd355 100644
--- a/repo.go
+++ b/repo.go
@@ -297,6 +297,16 @@ func loadBasicStruct(path string, wrapper utils.ReadWrapper, obj interface{}) {
}
}
+func (r *Repo) loadDeltas(versions []string, name string) (ret slice.Slice) {
+ for _, v := range versions {
+ path := filepath.Join(v, name)
+ var delta slice.Delta
+ loadBasicStruct(path, utils.ZlibReader, &delta)
+ ret = slice.Patch(ret, delta)
+ }
+ return
+}
+
func storeFileList(dest string, files []File) {
storeBasicStruct(dest, utils.ZlibWriter, files)
}
@@ -641,9 +651,6 @@ func (r *Repo) matchStream(stream io.Reader, version int) []Chunk {
func (r *Repo) restoreStream(stream io.WriteCloser, recipe []Chunk) {
for _, c := range recipe {
- if rc, isRepo := c.(RepoChunk); isRepo {
- rc.SetRepo(r)
- }
if n, err := io.Copy(stream, c.Reader()); err != nil {
logger.Errorf("copying to stream, read %d bytes from chunk: %s", n, err)
}
@@ -652,7 +659,7 @@ func (r *Repo) restoreStream(stream io.WriteCloser, recipe []Chunk) {
}
func recipe2slice(r []Chunk) (ret slice.Slice) {
- ret = make(slice.Slice, len(r), len(r))
+ ret = make(slice.Slice, len(r))
for i := range r {
ret[i] = r[i]
}
@@ -673,19 +680,18 @@ func slice2recipe(s slice.Slice) (ret []Chunk) {
func (r *Repo) storeRecipe(version int, recipe []Chunk) {
dest := filepath.Join(r.path, fmt.Sprintf(versionFmt, version), recipeName)
- d := slice.Diff(recipe2slice(r.recipe), recipe2slice(recipe))
- storeBasicStruct(dest, utils.ZlibWriter, d)
+ delta := slice.Diff(recipe2slice(r.recipe), recipe2slice(recipe))
+ storeBasicStruct(dest, utils.ZlibWriter, delta)
}
func (r *Repo) loadRecipes(versions []string) {
- var s slice.Slice
- for _, v := range versions {
- path := filepath.Join(v, recipeName)
- var d slice.Delta
- loadBasicStruct(path, utils.ZlibReader, &d)
- s = slice.Patch(s, d)
+ recipe := slice2recipe(r.loadDeltas(versions, recipeName))
+ for _, c := range recipe {
+ if rc, isRepo := c.(RepoChunk); isRepo {
+ rc.SetRepo(r)
+ }
}
- r.recipe = slice2recipe(s)
+ r.recipe = recipe
}
func extractDeltaChunks(chunks []Chunk) (ret []*DeltaChunk) {