Skip to content

Commit

Permalink
control: Fix Installed-Size property calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Jacobs committed Jun 26, 2017
1 parent 92c3c96 commit ee225de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion control.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (c *control) String(installedSize uint64) string {
o += fmt.Sprintf("Maintainer: %s <%s>\n",
c.info.maintainer,
c.info.maintainerEmail)
o += fmt.Sprintf("Installed-Size: %d\n", uint64(math.Floor((float64(installedSize)/1024)+0.5)))
o += fmt.Sprintf("Installed-Size: %d\n", uint64(math.Ceil(float64(installedSize)/1024)))

if c.info.section != "" {
o += fmt.Sprintf("Section: %s\n", c.info.section)
Expand Down
42 changes: 42 additions & 0 deletions control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,45 @@ Description: Golang package for creating (gpg signed) debian packages
fmt.Printf("--- expected (len %d):\n'%s'\n--- got (len %d):\n'%s'---\n", len(controlExpect), controlExpect, len(control), control)
}
}

// Test correct output of a control file Installed-Size property
func TestControlInstalledSize(t *testing.T) {
controlExpect1K := `Package:
Version: 0.0.0
Architecture: amd64
Maintainer: <>
Installed-Size: 1
Description:
`
// Empty
deb := New()
defer deb.Close()

// architecture is auto-set when empty, this makes sure it is always set to amd64
deb.SetArchitecture("amd64")
control := deb.control.String(1024)

if control != controlExpect1K {
t.Error("Unexpected control file")
}

controlExpect2K := `Package:
Version: 0.0.0
Architecture: amd64
Maintainer: <>
Installed-Size: 2
Description:
`

// 1KByte + 1 byte
control = deb.control.String(1025)
if control != controlExpect2K {
t.Error("Unexpected control file")
}

// 2KByte
control = deb.control.String(2048)
if control != controlExpect2K {
t.Error("Unexpected control file")
}
}

0 comments on commit ee225de

Please sign in to comment.