From 906cbf1e6f1b4d150e68850f9a524a09e4afbb31 Mon Sep 17 00:00:00 2001 From: Shengjing Zhu Date: Sat, 13 Apr 2019 20:09:34 +0800 Subject: [PATCH] Fix time.Time msgpack decoding backwards compatibility See https://github.com/ugorji/go-codec/issues/269 --- deb/remote.go | 12 ++++++++++++ deb/snapshot.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/deb/remote.go b/deb/remote.go index 72165baf..7be9cda3 100644 --- a/deb/remote.go +++ b/deb/remote.go @@ -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 } diff --git a/deb/snapshot.go b/deb/snapshot.go index aef19ae4..46fb438f 100644 --- a/deb/snapshot.go +++ b/deb/snapshot.go @@ -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 }