Skip to content

Commit

Permalink
Use int64 to hold database size in bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Apr 13, 2019
1 parent 3793fde commit c659428
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ 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
b, err := ioutil.ReadFile(db)
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))
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/dio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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?
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/releaseCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c659428

Please sign in to comment.