Check errors and enable errcheck in lint config (#2242)

This commit is contained in:
Carlo Teubner authored and GitHub committed 2025-11-10 10:17:18 +01:00
1 parent b6535060a6
commit 8da478bb86
11 files changed
+120 -48

No files matched your search

+25 -15
View File
@@ -54,10 +54,11 @@ func copySize(srcs []string) (int64, error) {
return total, nil
}
func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan int64) error {
func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan<- int64, errs chan<- error) {
r, err := os.Open(src)
if err != nil {
return err
errs <- err
return
}
defer r.Close()
@@ -67,30 +68,38 @@ func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan in
}
w, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, dstMode)
if err != nil {
return err
errs <- err
return
}
if _, err := io.Copy(NewProgressWriter(w, nums), r); err != nil {
errs <- err
w.Close()
os.Remove(dst)
return err
if err = os.Remove(dst); err != nil {
errs <- err
}
return
}
if err := w.Close(); err != nil {
os.Remove(dst)
return err
errs <- err
if err = os.Remove(dst); err != nil {
errs <- err
}
return
}
if slices.Contains(preserve, "timestamps") {
atime := times.Get(info).AccessTime()
mtime := info.ModTime()
if err := os.Chtimes(dst, atime, mtime); err != nil {
os.Remove(dst)
return err
errs <- err
if err = os.Remove(dst); err != nil {
errs <- err
}
return
}
}
return nil
}
func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, errs chan error) {
@@ -119,7 +128,7 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
dst = newPath
}
filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
errs <- fmt.Errorf("walk: %w", err)
return nil
@@ -153,12 +162,13 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
}
nums <- info.Size()
default:
if err := copyFile(path, newPath, preserve, info, nums); err != nil {
errs <- fmt.Errorf("copy: %w", err)
}
copyFile(path, newPath, preserve, info, nums, errs)
}
return nil
})
if err != nil {
errs <- fmt.Errorf("walk: %w", err)
}
}
for path, info := range dirInfos {