Skip to content

Commit

Permalink
Fix time.Time msgpack decoding backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zhsj committed Apr 13, 2019
1 parent 56c4d5b commit ba7040b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions deb/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions deb/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ba7040b

Please sign in to comment.