mirror of
https://github.com/minio/minio.git
synced 2024-12-29 08:33:21 -05:00
eb7c690ea9
This PR allows 'minio update' to not only shows update banner but also allows for in-place upgrades. Updates are done safely by validating the downloaded sha256 of the binary. Fixes #4781
44 lines
774 B
Go
44 lines
774 B
Go
package binarydist
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
type seekBuffer struct {
|
|
buf []byte
|
|
pos int
|
|
}
|
|
|
|
func (b *seekBuffer) Write(p []byte) (n int, err error) {
|
|
n = copy(b.buf[b.pos:], p)
|
|
if n == len(p) {
|
|
b.pos += n
|
|
return n, nil
|
|
}
|
|
b.buf = append(b.buf, p[n:]...)
|
|
b.pos += len(p)
|
|
return len(p), nil
|
|
}
|
|
|
|
func (b *seekBuffer) Seek(offset int64, whence int) (ret int64, err error) {
|
|
var abs int64
|
|
switch whence {
|
|
case 0:
|
|
abs = offset
|
|
case 1:
|
|
abs = int64(b.pos) + offset
|
|
case 2:
|
|
abs = int64(len(b.buf)) + offset
|
|
default:
|
|
return 0, errors.New("binarydist: invalid whence")
|
|
}
|
|
if abs < 0 {
|
|
return 0, errors.New("binarydist: negative position")
|
|
}
|
|
if abs >= 1<<31 {
|
|
return 0, errors.New("binarydist: position out of range")
|
|
}
|
|
b.pos = int(abs)
|
|
return abs, nil
|
|
}
|