Add patch to fix DB backwards compatibility (Closes: #911924)
Shengjing Zhu
5 years ago
0 | From: Shengjing Zhu <zhsj@debian.org> | |
1 | Date: Sat, 13 Apr 2019 22:57:46 +0800 | |
2 | Subject: Fix time.Time msgpack decoding backwards compatibility | |
3 | ||
4 | This allows aptly to decode DB created by old codec library. | |
5 | ||
6 | Forwarded: https://github.com/aptly-dev/aptly/pull/830 | |
7 | --- | |
8 | deb/remote.go | 3 ++- | |
9 | deb/snapshot.go | 3 ++- | |
10 | 2 files changed, 4 insertions(+), 2 deletions(-) | |
11 | ||
12 | diff --git a/deb/remote.go b/deb/remote.go | |
13 | index 167d45f..71eb984 100644 | |
14 | --- a/deb/remote.go | |
15 | +++ b/deb/remote.go | |
16 | @@ -600,7 +600,8 @@ func (repo *RemoteRepo) Decode(input []byte) error { | |
17 | decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{}) | |
18 | err := decoder.Decode(repo) | |
19 | if err != nil { | |
20 | - if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") { | |
21 | + if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") || | |
22 | + strings.Contains(err.Error(), "invalid length of bytes for decoding time") { | |
23 | // probably it is broken DB from go < 1.2, try decoding w/o time.Time | |
24 | var repo11 struct { // nolint: maligned | |
25 | UUID string | |
26 | diff --git a/deb/snapshot.go b/deb/snapshot.go | |
27 | index fc7689c..feef44a 100644 | |
28 | --- a/deb/snapshot.go | |
29 | +++ b/deb/snapshot.go | |
30 | @@ -140,7 +140,8 @@ func (s *Snapshot) Decode(input []byte) error { | |
31 | decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{}) | |
32 | err := decoder.Decode(s) | |
33 | if err != nil { | |
34 | - if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") { | |
35 | + if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") || | |
36 | + strings.Contains(err.Error(), "invalid length of bytes for decoding time") { | |
37 | // probably it is broken DB from go < 1.2, try decoding w/o time.Time | |
38 | var snapshot11 struct { | |
39 | UUID string |