Fix time.Time msgpack decoding backwards compatibility

See https://github.com/ugorji/go-codec/issues/269
This commit is contained in:
Shengjing Zhu
2019-04-13 20:09:34 +08:00
committed by Andrey Smirnov
parent 5aefc741f2
commit 906cbf1e6f
2 changed files with 24 additions and 0 deletions
+12
View File
@@ -696,6 +696,18 @@ func (repo *RemoteRepo) Decode(input []byte) error {
repo.ReleaseFiles = repo11.ReleaseFiles
repo.Filter = repo11.Filter
repo.FilterWithDeps = repo11.FilterWithDeps
} else if strings.Contains(err.Error(), "invalid length of bytes for decoding time") {
// DB created by old codec version, time.Time is not builtin type.
// https://github.com/ugorji/go-codec/issues/269
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{
// only can be configured in Deprecated BasicHandle struct
BasicHandle: codec.BasicHandle{ // nolint: staticcheck
TimeNotBuiltin: true,
},
})
if err = decoder.Decode(repo); err != nil {
return err
}
} else {
return err
}
+12
View File
@@ -163,6 +163,18 @@ func (s *Snapshot) Decode(input []byte) error {
s.SourceKind = snapshot11.SourceKind
s.SourceIDs = snapshot11.SourceIDs
s.Description = snapshot11.Description
} else if strings.Contains(err.Error(), "invalid length of bytes for decoding time") {
// DB created by old codec version, time.Time is not builtin type.
// https://github.com/ugorji/go-codec/issues/269
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{
// only can be configured in Deprecated BasicHandle struct
BasicHandle: codec.BasicHandle{ // nolint: staticcheck
TimeNotBuiltin: true,
},
})
if err = decoder.Decode(s); err != nil {
return err
}
} else {
return err
}