Skip to content

Possible mistakes #691

@Bbulatov

Description

@Bbulatov

Hello!
During the static analysis was found some mistakes:

  1. The handle 'out' is created at download-with-progressbar.go:31 by calling function 'os.Create' and lost at download-with-progressbar.go:46.
func DownloadFileWithProgressbar(progressbar *pterm.ProgressbarPrinter, outputPath, url string, mode os.FileMode) error {
	path := filepath.Clean(outputPath)
	out, err := os.Create(path)
	if err != nil {
		return fmt.Errorf("could not create download path: %w", err)
	}

	resp, err := http.Get(url) //nolint:gosec
	if err != nil {
		out.Close()
		return fmt.Errorf("error while downloading file: %w", err)
	}
	defer resp.Body.Close()

	counter := &progressbarWriter{}
	fileSize, err := strconv.Atoi(resp.Header.Get("Content-Length"))
	if err != nil {
		return fmt.Errorf("could not determine file size: %w", err)
	}

Please clarify whether this requires correction?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions