Fix all linter errors

- Add explicit error ignoring with _ = for Close/Remove calls
- Rename WriteTo to Write to avoid io.WriterTo interface conflict
- Fix errcheck warnings in fetch, freshen, gen, mfer, checker,
  deserialize, serialize, and output files
This commit is contained in:
2025-12-17 14:37:52 -08:00
parent 531f460f87
commit 92bd13efde
9 changed files with 35 additions and 35 deletions

View File

@@ -48,7 +48,7 @@ func (mfa *CLIApp) fetchManifestOperation(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to fetch manifest: %w", err)
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to fetch manifest: HTTP %d", resp.StatusCode)
@@ -283,7 +283,7 @@ func downloadFile(fileURL, localPath string, entry *mfer.MFFilePath, progress ch
if err != nil {
return err
}
defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("HTTP %d", resp.StatusCode)
@@ -322,24 +322,24 @@ func downloadFile(fileURL, localPath string, entry *mfer.MFFilePath, progress ch
// If copy failed, clean up temp file and return error
if copyErr != nil {
os.Remove(tmpPath)
_ = os.Remove(tmpPath)
return copyErr
}
if closeErr != nil {
os.Remove(tmpPath)
_ = os.Remove(tmpPath)
return closeErr
}
// Verify size
if written != expectedSize {
os.Remove(tmpPath)
_ = os.Remove(tmpPath)
return fmt.Errorf("size mismatch: expected %d bytes, got %d", expectedSize, written)
}
// Encode computed hash as multihash
computed, err := multihash.Encode(h.Sum(nil), multihash.SHA2_256)
if err != nil {
os.Remove(tmpPath)
_ = os.Remove(tmpPath)
return fmt.Errorf("failed to encode hash: %w", err)
}
@@ -352,13 +352,13 @@ func downloadFile(fileURL, localPath string, entry *mfer.MFFilePath, progress ch
}
}
if !hashMatch {
os.Remove(tmpPath)
_ = os.Remove(tmpPath)
return fmt.Errorf("hash mismatch")
}
// Rename temp file to final path
if err := os.Rename(tmpPath, localPath); err != nil {
os.Remove(tmpPath)
_ = os.Remove(tmpPath)
return fmt.Errorf("failed to rename temp file: %w", err)
}