MM-46455 Remove download limit (#20870)
* [MM-46455] Raise download limit and add errors for exceeding it * [MM-46455] Report HTTP errors * Remove download size limit Co-authored-by: Tim Scheuermann <tim.scheuermann@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e3efc46f69
Коммит
617eb98d29
@@ -202,7 +202,7 @@ func UpgradeToE0() error {
|
||||
return err
|
||||
}
|
||||
|
||||
filename, err := download(getCurrentVersionTgzURL(), 1024*1024*300)
|
||||
filename, err := download(getCurrentVersionTgzURL())
|
||||
if err != nil {
|
||||
if filename != "" {
|
||||
os.Remove(filename)
|
||||
@@ -213,7 +213,8 @@ func UpgradeToE0() error {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(filename)
|
||||
sigfilename, err := download(getCurrentVersionTgzURL()+".sig", 1024)
|
||||
|
||||
sigfilename, err := download(getCurrentVersionTgzURL() + ".sig")
|
||||
if err != nil {
|
||||
if sigfilename != "" {
|
||||
os.Remove(sigfilename)
|
||||
@@ -249,13 +250,18 @@ func UpgradeToE0Status() (int64, error) {
|
||||
return getUpgradePercentage(), getUpgradeError()
|
||||
}
|
||||
|
||||
func download(url string, limit int64) (string, error) {
|
||||
func download(url string) (string, error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
return "", errors.Errorf("error downloading file %s: %s", url, resp.Status)
|
||||
}
|
||||
|
||||
out, err := os.CreateTemp("", "*_mattermost.tar.gz")
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -263,8 +269,12 @@ func download(url string, limit int64) (string, error) {
|
||||
defer out.Close()
|
||||
|
||||
counter := &writeCounter{total: resp.ContentLength}
|
||||
_, err = io.Copy(out, io.TeeReader(&io.LimitedReader{R: resp.Body, N: limit}, counter))
|
||||
return out.Name(), err
|
||||
_, err = io.Copy(out, io.TeeReader(resp.Body, counter))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return out.Name(), nil
|
||||
}
|
||||
|
||||
func getFilePermissionsOrDefault(filename string, def os.FileMode) os.FileMode {
|
||||
|
||||
Ссылка в новой задаче
Block a user