mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Workaround for broken time.Time encoding in msgpack with go < 1.2. #89
Decoding looses value of time.Time field, but that is not critical.
This commit is contained in:
+37
-1
@@ -502,7 +502,43 @@ func (repo *RemoteRepo) Decode(input []byte) error {
|
|||||||
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
||||||
err := decoder.Decode(repo)
|
err := decoder.Decode(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") {
|
||||||
|
// probably it is broken DB from go < 1.2, try decoding w/o time.Time
|
||||||
|
var repo11 struct {
|
||||||
|
UUID string
|
||||||
|
Name string
|
||||||
|
ArchiveRoot string
|
||||||
|
Distribution string
|
||||||
|
Components []string
|
||||||
|
Architectures []string
|
||||||
|
DownloadSources bool
|
||||||
|
Meta Stanza
|
||||||
|
LastDownloadDate []byte
|
||||||
|
ReleaseFiles map[string]utils.ChecksumInfo
|
||||||
|
Filter string
|
||||||
|
FilterWithDeps bool
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder = codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
||||||
|
err2 := decoder.Decode(&repo11)
|
||||||
|
if err2 != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.UUID = repo11.UUID
|
||||||
|
repo.Name = repo11.Name
|
||||||
|
repo.ArchiveRoot = repo11.ArchiveRoot
|
||||||
|
repo.Distribution = repo11.Distribution
|
||||||
|
repo.Components = repo11.Components
|
||||||
|
repo.Architectures = repo11.Architectures
|
||||||
|
repo.DownloadSources = repo11.DownloadSources
|
||||||
|
repo.Meta = repo11.Meta
|
||||||
|
repo.ReleaseFiles = repo11.ReleaseFiles
|
||||||
|
repo.Filter = repo11.Filter
|
||||||
|
repo.FilterWithDeps = repo11.FilterWithDeps
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return repo.prepare()
|
return repo.prepare()
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-1
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/smira/aptly/utils"
|
"github.com/smira/aptly/utils"
|
||||||
"github.com/ugorji/go/codec"
|
"github.com/ugorji/go/codec"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -125,7 +126,36 @@ func (s *Snapshot) Encode() []byte {
|
|||||||
// Decode decodes msgpack representation into Snapshot
|
// Decode decodes msgpack representation into Snapshot
|
||||||
func (s *Snapshot) Decode(input []byte) error {
|
func (s *Snapshot) Decode(input []byte) error {
|
||||||
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
||||||
return decoder.Decode(s)
|
err := decoder.Decode(s)
|
||||||
|
if err != nil {
|
||||||
|
if strings.HasPrefix(err.Error(), "codec.decoder: readContainerLen: Unrecognized descriptor byte: hex: 80") {
|
||||||
|
// probably it is broken DB from go < 1.2, try decoding w/o time.Time
|
||||||
|
var snapshot11 struct {
|
||||||
|
UUID string
|
||||||
|
Name string
|
||||||
|
CreatedAt []byte
|
||||||
|
|
||||||
|
SourceKind string
|
||||||
|
SourceIDs []string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder = codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
|
||||||
|
err2 := decoder.Decode(&snapshot11)
|
||||||
|
if err2 != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.UUID = snapshot11.UUID
|
||||||
|
s.Name = snapshot11.Name
|
||||||
|
s.SourceKind = snapshot11.SourceKind
|
||||||
|
s.SourceIDs = snapshot11.SourceIDs
|
||||||
|
s.Description = snapshot11.Description
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SnapshotCollection does listing, updating/adding/deleting of Snapshots
|
// SnapshotCollection does listing, updating/adding/deleting of Snapshots
|
||||||
|
|||||||
Reference in New Issue
Block a user