mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-05 13:11:30 +00:00
Fix uses of "int" where "int64" should be used instead
Some structures use int for sizes and UNIX timestamps. On some platforms, int is 32 bits, so this can lead to the year 2038 issues and overflows when dealing with large containers or layers. Consistently use int64 to store sizes and UNIX timestamps in api/types/types.go. Update related to code accordingly (i.e. strconv.FormatInt instead of strconv.Itoa). Use int64 in progressreader package to avoid integer overflow when dealing with large quantities. Update related code accordingly. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
@@ -14,9 +14,9 @@ type Config struct {
|
||||
In io.ReadCloser // Stream to read from
|
||||
Out io.Writer // Where to send progress bar to
|
||||
Formatter *streamformatter.StreamFormatter
|
||||
Size int
|
||||
Current int
|
||||
LastUpdate int
|
||||
Size int64
|
||||
Current int64
|
||||
LastUpdate int64
|
||||
NewLines bool
|
||||
ID string
|
||||
Action string
|
||||
@@ -29,11 +29,11 @@ func New(newReader Config) *Config {
|
||||
|
||||
func (config *Config) Read(p []byte) (n int, err error) {
|
||||
read, err := config.In.Read(p)
|
||||
config.Current += read
|
||||
updateEvery := 1024 * 512 //512kB
|
||||
config.Current += int64(read)
|
||||
updateEvery := int64(1024 * 512) //512kB
|
||||
if config.Size > 0 {
|
||||
// Update progress for every 1% read if 1% < 512kB
|
||||
if increment := int(0.01 * float64(config.Size)); increment < updateEvery {
|
||||
if increment := int64(0.01 * float64(config.Size)); increment < updateEvery {
|
||||
updateEvery = increment
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestOutputOnPrematureClose(t *testing.T) {
|
||||
In: reader,
|
||||
Out: writer,
|
||||
Formatter: streamformatter.NewStreamFormatter(),
|
||||
Size: len(content),
|
||||
Size: int64(len(content)),
|
||||
NewLines: true,
|
||||
ID: "Test",
|
||||
Action: "Read",
|
||||
@@ -60,7 +60,7 @@ func TestCompleteSilently(t *testing.T) {
|
||||
In: reader,
|
||||
Out: writer,
|
||||
Formatter: streamformatter.NewStreamFormatter(),
|
||||
Size: len(content),
|
||||
Size: int64(len(content)),
|
||||
NewLines: true,
|
||||
ID: "Test",
|
||||
Action: "Read",
|
||||
|
||||
Reference in New Issue
Block a user