aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-10-13 15:42:17 +0200
committern-peugnet <n.peugnet@free.fr>2021-10-13 16:07:14 +0200
commitd38e6e0cf5a9790f4e774f6900c4b02a62e9e034 (patch)
tree47ef96f4656ee615a96ed2e8bccf9c2de24eb1d4
parent57bd3d4633a85f5cf103aae1dd6f0f607a26ef8c (diff)
downloaddna-backup-d38e6e0cf5a9790f4e774f6900c4b02a62e9e034.tar.gz
dna-backup-d38e6e0cf5a9790f4e774f6900c4b02a62e9e034.zip
try to make loadDeltas more robust aginst code change
-rw-r--r--repo/repo.go24
-rw-r--r--repo/testdata/repo_8k_zlib/00000/filesbin114 -> 169 bytes
-rw-r--r--repo/testdata/repo_8k_zlib/00000/hashesbin570 -> 570 bytes
-rw-r--r--repo/testdata/repo_8k_zlib/00000/recipebin2084 -> 2095 bytes
4 files changed, 7 insertions, 17 deletions
diff --git a/repo/repo.go b/repo/repo.go
index 27df54e..b8c07f2 100644
--- a/repo/repo.go
+++ b/repo/repo.go
@@ -337,14 +337,7 @@ func storeDelta(prevRaw []byte, curr interface{}, dest string, differ delta.Diff
var encoder *gob.Encoder
var err error
- if len(prevRaw) == 0 {
- encoder = gob.NewEncoder(&prevBuff)
- if err = encoder.EncodeValue(reflect.ValueOf(curr)); err != nil {
- logger.Panic(err)
- }
- } else {
- prevBuff = *bytes.NewBuffer(prevRaw)
- }
+ prevBuff = *bytes.NewBuffer(prevRaw)
encoder = gob.NewEncoder(&currBuff)
if err = encoder.Encode(curr); err != nil {
logger.Panic(err)
@@ -366,16 +359,10 @@ func storeDelta(prevRaw []byte, curr interface{}, dest string, differ delta.Diff
}
}
-func loadDeltas(target interface{}, versions []string, patcher delta.Patcher, wrapper utils.ReadWrapper, name string) []byte {
+func loadDeltas(target interface{}, versions []string, patcher delta.Patcher, wrapper utils.ReadWrapper, name string) (ret []byte) {
var prev bytes.Buffer
- var encoder *gob.Encoder
var err error
- encoder = gob.NewEncoder(&prev)
- if err = encoder.Encode(target); err != nil {
- logger.Panic(err)
- }
-
for _, v := range versions {
var curr bytes.Buffer
path := filepath.Join(v, name)
@@ -398,12 +385,15 @@ func loadDeltas(target interface{}, versions []string, patcher delta.Patcher, wr
logger.Panic(err)
}
}
- ret := prev.Bytes()
+ ret = prev.Bytes()
+ if len(ret) == 0 {
+ return
+ }
decoder := gob.NewDecoder(&prev)
if err = decoder.Decode(target); err != nil {
logger.Panic(err)
}
- return ret
+ return
}
// storeFileList stores the given list in the repo dir as a delta against the
diff --git a/repo/testdata/repo_8k_zlib/00000/files b/repo/testdata/repo_8k_zlib/00000/files
index e9bb403..98a7a44 100644
--- a/repo/testdata/repo_8k_zlib/00000/files
+++ b/repo/testdata/repo_8k_zlib/00000/files
Binary files differ
diff --git a/repo/testdata/repo_8k_zlib/00000/hashes b/repo/testdata/repo_8k_zlib/00000/hashes
index 8c6a857..ec622b2 100644
--- a/repo/testdata/repo_8k_zlib/00000/hashes
+++ b/repo/testdata/repo_8k_zlib/00000/hashes
Binary files differ
diff --git a/repo/testdata/repo_8k_zlib/00000/recipe b/repo/testdata/repo_8k_zlib/00000/recipe
index 7d33a6a..ef8e6d1 100644
--- a/repo/testdata/repo_8k_zlib/00000/recipe
+++ b/repo/testdata/repo_8k_zlib/00000/recipe
Binary files differ