Unverified Commit 7a36aa04 authored by Pedro Pombeiro's avatar Pedro Pombeiro
Browse files

Add more fixes missed by golangci-lint and found by standalone errcheck

parent 08cb5c03
......@@ -293,7 +293,7 @@ func (b *buildsHelper) ListJobsHandler(w http.ResponseWriter, r *http.Request) {
for _, job := range b.builds {
url := CreateJobURL(job.RepoCleanURL(), job.ID)
fmt.Fprintf(
_, _ = fmt.Fprintf(
w,
"url=%s state=%s stage=%s executor_stage=%s duration=%s\n",
url, job.CurrentState, job.CurrentStage, job.CurrentExecutorStage(), job.Duration(),
......
......@@ -64,8 +64,8 @@ func (c *ArtifactsDownloaderCommand) Execute(context *cli.Context) {
if err != nil {
logrus.Fatalln(err)
}
file.Close()
defer os.Remove(file.Name())
_ = file.Close()
defer func() { _ = os.Remove(file.Name()) }()
// Download artifacts file
err = c.doRetry(func(retry int) error {
......
......@@ -101,7 +101,7 @@ func (c *ArtifactsUploaderCommand) Run() error {
return nil
}
defer stream.Close()
defer func() { _ = stream.Close() }()
// Create the archive
options := common.ArtifactsOptions{
......
......@@ -40,7 +40,7 @@ func (c *CacheArchiverCommand) upload(_ int) error {
if err != nil {
return err
}
defer file.Close()
defer func() { _ = file.Close() }()
fi, err := file.Stat()
if err != nil {
......@@ -59,7 +59,7 @@ func (c *CacheArchiverCommand) upload(_ int) error {
if err != nil {
return retryableErr{err: err}
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
return retryOnServerError(resp)
}
......
......@@ -51,7 +51,7 @@ func (c *CacheExtractorCommand) download(_ int) error {
return err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
upToDate, date := checkIfUpToDate(c.File, resp)
if upToDate {
......@@ -63,8 +63,10 @@ func (c *CacheExtractorCommand) download(_ int) error {
if err != nil {
return err
}
defer os.Remove(file.Name())
defer file.Close()
defer func() {
_ = file.Close()
_ = os.Remove(file.Name())
}()
logrus.Infoln("Downloading", filepath.Base(c.File), "from", url_helpers.CleanURL(c.URL))
_, err = io.Copy(file, resp.Body)
......@@ -96,7 +98,7 @@ func (c *CacheExtractorCommand) getCache() (*http.Response, error) {
}
if resp.StatusCode == http.StatusNotFound {
resp.Body.Close()
_ = resp.Body.Close()
return nil, os.ErrNotExist
}
......
......@@ -35,7 +35,7 @@ func (c *HealthCheckCommand) Execute(ctx *cli.Context) {
logrus.Fatalln("No HOST or PORT found")
}
fmt.Fprintf(os.Stdout, "waiting for TCP connection to %s:%s...", addr, port)
_, _ = fmt.Fprintf(os.Stdout, "waiting for TCP connection to %s:%s...", addr, port)
for {
conn, err := net.Dial("tcp", net.JoinHostPort(addr, port))
......@@ -44,7 +44,7 @@ func (c *HealthCheckCommand) Execute(ctx *cli.Context) {
continue
}
conn.Close()
_ = conn.Close()
return
}
}
......
......@@ -54,7 +54,7 @@ func retryOnServerError(resp *http.Response) error {
return nil
}
resp.Body.Close()
_ = resp.Body.Close()
err := fmt.Errorf("received: %s", resp.Status)
......
......@@ -22,7 +22,7 @@ func (e *BuildLogger) WithFields(fields logrus.Fields) BuildLogger {
func (e *BuildLogger) SendRawLog(args ...interface{}) {
if e.log != nil {
fmt.Fprint(e.log, args...)
_, _ = fmt.Fprint(e.log, args...)
}
}
......
......@@ -323,7 +323,7 @@ func getGitLabComTLSChain() (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
var buff bytes.Buffer
for _, certs := range resp.TLS.VerifiedChains {
......
......@@ -243,7 +243,7 @@ func (e *executor) Cleanup() {
return
}
defer os.RemoveAll(e.tempDir)
defer func() { _ = os.RemoveAll(e.tempDir) }()
// nothing to do, as there's no cleanup_script
if e.config.CleanupExec == "" {
......
......@@ -212,7 +212,7 @@ func (e *executor) loadPrebuiltImage(path, ref, tag string) (*types.ImageInspect
return nil, fmt.Errorf("cannot load prebuilt image: %s: %w", path, err)
}
defer file.Close()
defer func() { _ = file.Close() }()
e.Debugln("Loading prebuilt image...")
......@@ -1186,7 +1186,7 @@ func (e *executor) Cleanup() {
}
if e.client != nil {
e.client.Close()
_ = e.client.Close()
}
e.AbstractExecutor.Cleanup()
......@@ -1385,7 +1385,7 @@ func (e *executor) readContainerLogs(containerID string) string {
if err != nil {
return strings.TrimSpace(err.Error())
}
defer hijacked.Close()
defer func() { _ = hijacked.Close() }()
_, _ = stdcopy.StdCopy(&containerBuffer, &containerBuffer, hijacked)
containerLog := containerBuffer.String()
......
......@@ -69,8 +69,8 @@ func (d *machinesData) writeDebugInformation() {
if err != nil {
return
}
defer file.Close()
fmt.Fprintln(file,
defer func() { _ = file.Close() }()
_, _ = fmt.Fprintln(file,
"time", time.Now(),
"runner", d.Runner,
"acquired", d.Acquired,
......
......@@ -158,7 +158,13 @@ func getPodPhase(c *kubernetes.Clientset, pod *api.Pod, out io.Writer) podPhaseR
}
}
fmt.Fprintf(out, "Waiting for pod %s/%s to be running, status is %s\n", pod.Namespace, pod.Name, pod.Status.Phase)
_, _ = fmt.Fprintf(
out,
"Waiting for pod %s/%s to be running, status is %s\n",
pod.Namespace,
pod.Name,
pod.Status.Phase,
)
return podPhaseResponse{false, pod.Status.Phase, nil}
}
......
......@@ -54,7 +54,7 @@ func (s *StubSSHServer) Start() (int, error) {
go func() {
<-s.stop
s.shouldExit.Set()
listener.Close()
_ = listener.Close()
}()
address := strings.SplitN(listener.Addr().String(), ":", 2)
......
......@@ -18,13 +18,13 @@ func writeGzipFile(w io.Writer, fileName string, fileInfo os.FileInfo) error {
gz.Header.Name = fileInfo.Name()
gz.Header.Comment = fileName
gz.Header.ModTime = fileInfo.ModTime()
defer gz.Close()
defer func() { _ = gz.Close() }()
file, err := os.Open(fileName)
if err != nil {
return err
}
defer file.Close()
defer func() { _ = file.Close() }()
_, err = io.Copy(gz, file)
return err
......
......@@ -44,7 +44,7 @@ func createZipFileEntry(archive *zip.Writer, fh *zip.FileHeader) error {
}
_, err = io.Copy(fw, file)
file.Close()
_ = file.Close()
if err != nil {
return err
}
......@@ -86,7 +86,7 @@ func CreateZipArchive(w io.Writer, fileNames []string) error {
tracker := newPathErrorTracker()
archive := zip.NewWriter(w)
defer archive.Close()
defer func() { _ = archive.Close() }()
for _, fileName := range fileNames {
if err := errorIfGitDirectory(fileName); tracker.actionable(err) {
......@@ -113,15 +113,17 @@ func CreateZipFile(fileName string, fileNames []string) error {
if err != nil {
return err
}
defer tempFile.Close()
defer os.Remove(tempFile.Name())
defer func() {
_ = tempFile.Close()
_ = os.Remove(tempFile.Name())
}()
logrus.Debugln("Temporary file:", tempFile.Name())
err = CreateZipArchive(tempFile, fileNames)
if err != nil {
return err
}
tempFile.Close()
_ = tempFile.Close()
err = os.Rename(tempFile.Name(), fileName)
if err != nil {
......
......@@ -26,7 +26,7 @@ func extractZipSymlinkEntry(file *zip.File) (err error) {
if err != nil {
return err
}
defer in.Close()
defer func() { _ = in.Close() }()
data, err = ioutil.ReadAll(in)
if err != nil {
......@@ -34,7 +34,7 @@ func extractZipSymlinkEntry(file *zip.File) (err error) {
}
// Remove symlink before creating a new one, otherwise we can error that file does exist
os.Remove(file.Name)
_ = os.Remove(file.Name)
err = os.Symlink(string(data), file.Name)
return
}
......@@ -45,15 +45,15 @@ func extractZipFileEntry(file *zip.File) (err error) {
if err != nil {
return err
}
defer in.Close()
defer func() { _ = in.Close() }()
// Remove file before creating a new one, otherwise we can error that file does exist
os.Remove(file.Name)
_ = os.Remove(file.Name)
out, err = os.OpenFile(file.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode().Perm())
if err != nil {
return err
}
defer out.Close()
defer func() { _ = out.Close() }()
_, err = io.Copy(out, in)
return
......@@ -116,7 +116,7 @@ func ExtractZipFile(fileName string) error {
if err != nil {
return err
}
defer archive.Close()
defer func() { _ = archive.Close() }()
return ExtractZipArchive(&archive.Reader)
}
......@@ -18,7 +18,7 @@ func FixHOME(app *cli.App) {
if value == "" {
return fmt.Errorf("the %q is not set", key)
}
os.Setenv(key, value)
_ = os.Setenv(key, value)
}
if appBefore != nil {
......
......@@ -259,7 +259,7 @@ func (c *officialDockerClient) ImageImportBlocking(
if err != nil {
return wrapError("ImageImport", err, started)
}
defer readCloser.Close()
defer func() { _ = readCloser.Close() }()
// TODO: respect the context here
if _, err := io.Copy(ioutil.Discard, readCloser); err != nil {
......@@ -278,7 +278,7 @@ func (c *officialDockerClient) ImagePullBlocking(
if err != nil {
return wrapError("ImagePull", err, started)
}
defer readCloser.Close()
defer func() { _ = readCloser.Close() }()
// TODO: respect the context here
if _, err := io.Copy(ioutil.Discard, readCloser); err != nil {
......
......@@ -18,7 +18,7 @@ func (s *fatalLogHook) Levels() []logrus.Level {
}
func (s *fatalLogHook) Fire(e *logrus.Entry) error {
fmt.Fprint(s.output, e.Message)
_, _ = fmt.Fprint(s.output, e.Message)
panic(e)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment