From c659428f249df9196014ca69f4d73763a60ee9d5 Mon Sep 17 00:00:00 2001 From: Justin Clift Date: Sun, 14 Apr 2019 04:08:15 +1000 Subject: [PATCH] Use int64 to hold database size in bytes --- cmd/commit.go | 4 ++-- cmd/dio_test.go | 12 ++++++------ cmd/releaseCreate.go | 2 +- cmd/shared.go | 4 ++-- cmd/types.go | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/commit.go b/cmd/commit.go index 0bdfe2d..0be7c7a 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -238,7 +238,7 @@ func commit(args []string) error { // * Collect info for the new commit * // Get file size and last modified time for the database - fileSize := int(fi.Size()) + fileSize := fi.Size() lastModified := fi.ModTime() // Verify we've read the file from disk ok @@ -246,7 +246,7 @@ func commit(args []string) error { if err != nil { return err } - if len(b) != fileSize { + if int64(len(b)) != fileSize { return errors.New(numFormat.Sprintf("Aborting: # of bytes read (%d) when generating commit don't "+ "match database file size (%d)", len(b), fileSize)) } diff --git a/cmd/dio_test.go b/cmd/dio_test.go index f520d47..bf4508c 100644 --- a/cmd/dio_test.go +++ b/cmd/dio_test.go @@ -252,7 +252,7 @@ func (s *DioSuite) Test0010_Commit(c *chk.C) { c.Check(com.Tree.Entries[0].EntryType, chk.Equals, dbTreeEntryType(DATABASE)) c.Check(com.Tree.Entries[0].LastModified.UTC(), chk.Equals, time.Date(2019, time.March, 15, 18, 1, 0, 0, time.UTC)) c.Check(com.Tree.Entries[0].LicenceSHA, chk.Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") // e3b... is the SHA256 for the "Not specified" licence option - c.Check(com.Tree.Entries[0].Size, chk.Equals, 19456) + c.Check(int(com.Tree.Entries[0].Size), chk.Equals, 19456) c.Check(com.Tree.Entries[0].Name, chk.Equals, s.dbName) // Check the database has been written to the cache area using its checksum as filename @@ -263,7 +263,7 @@ func (s *DioSuite) Test0010_Commit(c *chk.C) { // Verify the contents of the cached database match the size and sha256 recorded in the commit b, err := ioutil.ReadFile(cacheFile) c.Assert(err, chk.IsNil) - c.Check(b, chk.HasLen, com.Tree.Entries[0].Size) + c.Check(b, chk.HasLen, int(com.Tree.Entries[0].Size)) z := sha256.Sum256(b) shaSum := hex.EncodeToString(z[:]) c.Check(shaSum, chk.Equals, com.Tree.Entries[0].Sha256) @@ -310,7 +310,7 @@ func (s *DioSuite) Test0020_Commit2(c *chk.C) { c.Check(com.Tree.Entries[0].EntryType, chk.Equals, dbTreeEntryType(DATABASE)) c.Check(com.Tree.Entries[0].LastModified.UTC(), chk.Equals, time.Date(2019, time.March, 15, 18, 1, 2, 0, time.UTC)) c.Check(com.Tree.Entries[0].LicenceSHA, chk.Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") // e3b... is the SHA256 for the "Not specified" licence option - c.Check(com.Tree.Entries[0].Size, chk.Equals, 19456) + c.Check(int(com.Tree.Entries[0].Size), chk.Equals, 19456) c.Check(com.Tree.Entries[0].Name, chk.Equals, s.dbName) // Check the database has been written to the cache area using its checksum as filename @@ -321,7 +321,7 @@ func (s *DioSuite) Test0020_Commit2(c *chk.C) { // Verify the contents of the cached database match the size and sha256 recorded in the commit b, err := ioutil.ReadFile(cacheFile) c.Assert(err, chk.IsNil) - c.Check(b, chk.HasLen, com.Tree.Entries[0].Size) + c.Check(b, chk.HasLen, int(com.Tree.Entries[0].Size)) z := sha256.Sum256(b) shaSum := hex.EncodeToString(z[:]) c.Check(shaSum, chk.Equals, com.Tree.Entries[0].Sha256) @@ -1455,7 +1455,7 @@ func mockServerNewDBPushHandler(w http.ResponseWriter, r *http.Request) { e.LicenceSHA = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" // SHA256 of "Not specified" licence e.Name = hdr.Filename e.Sha256 = shaSum - e.Size = int(numBytes) + e.Size = numBytes var t dbTree t.Entries = append(t.Entries, e) t.ID = createDBTreeID(t.Entries) @@ -1482,7 +1482,7 @@ func mockServerNewDBPushHandler(w http.ResponseWriter, r *http.Request) { Public: false, RepoModified: lastMod.UTC().Format(time.RFC3339), SHA256: expected["dbshasum"], - Size: int(numBytes), + Size: numBytes, Type: "database", URL: fmt.Sprintf("%s/default/%s?commit=%s&branch=%s", cloud, hdr.Filename, newCom.ID, expected["branch"]), // TODO: Is this the right URL, or is it supposed to be the user defined source URL? } diff --git a/cmd/releaseCreate.go b/cmd/releaseCreate.go index a5bfc95..4761e5e 100644 --- a/cmd/releaseCreate.go +++ b/cmd/releaseCreate.go @@ -113,7 +113,7 @@ func releaseCreate(args []string) error { Description: releaseCreateMsg, ReleaserEmail: releaseCreateCreatorEmail, ReleaserName: releaseCreateCreatorName, - Size: int(size), + Size: size, } // Add the new release to the local metadata cache diff --git a/cmd/shared.go b/cmd/shared.go index 503809a..19c4d38 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -118,7 +118,7 @@ func dbChanged(db string, meta metaData) (changed bool, err error) { } return } - fileSize := int(fi.Size()) + fileSize := fi.Size() lastModified := fi.ModTime().Truncate(time.Second).UTC() if metaFileSize != fileSize || !metaLastModified.Equal(lastModified) { changed = true @@ -134,7 +134,7 @@ func dbChanged(db string, meta metaData) (changed bool, err error) { if err != nil { return } - if len(b) != fileSize { + if int64(len(b)) != fileSize { err = errors.New(numFormat.Sprintf("Aborting: # of bytes read (%d) when reading the database "+ "doesn't match the database file size (%d)", len(b), fileSize)) return diff --git a/cmd/types.go b/cmd/types.go index 221bf2a..2b41b57 100644 --- a/cmd/types.go +++ b/cmd/types.go @@ -31,7 +31,7 @@ type dbListEntry struct { Public bool `json:"public"` RepoModified string `json:"repo_modified"` SHA256 string `json:"sha256"` - Size int `json:"size"` + Size int64 `json:"size"` Type string `json:"type"` URL string `json:"url"` } @@ -54,7 +54,7 @@ type dbTreeEntry struct { LicenceSHA string `json:"licence"` Name string `json:"name"` Sha256 string `json:"sha256"` - Size int `json:"size"` + Size int64 `json:"size"` } type defaultSettings struct { @@ -84,7 +84,7 @@ type releaseEntry struct { Description string `json:"description"` ReleaserEmail string `json:"email"` ReleaserName string `json:"name"` - Size int `json:"size"` + Size int64 `json:"size"` } type tagEntry struct {