From e1382125931c3962e68d641dfec951e7d164ed57 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Thu, 18 Dec 2014 11:13:16 +0100 Subject: [PATCH] Make files hash a type for proper JSON serialization --- deb/package.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/deb/package.go b/deb/package.go index 43e0a39b..8e1c1d0b 100644 --- a/deb/package.go +++ b/deb/package.go @@ -9,6 +9,8 @@ import ( "strings" ) +type Hash uint64 + // Package is single instance of Debian package type Package struct { // Basic package properties @@ -27,7 +29,7 @@ type Package struct { // Is this udeb package IsUdeb bool // Hash of files section - FilesHash uint64 + FilesHash Hash // Is this >= 0.6 package? V06Plus bool // Offload fields @@ -38,6 +40,10 @@ type Package struct { collection *PackageCollection } +func (h *Hash) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf("\"%08x\"", *h)), nil +} + // NewPackageFromControlFile creates Package from parsed Debian control file func NewPackageFromControlFile(input Stanza) *Package { result := &Package{ @@ -398,7 +404,7 @@ func (p *Package) Files() PackageFiles { // UpdateFiles saves new state of files func (p *Package) UpdateFiles(files PackageFiles) { p.files = &files - p.FilesHash = files.Hash() + p.FilesHash = Hash(files.Hash()) } // Stanza creates original stanza from package