Skip to content

Commit

Permalink
fix: CopyFromFs should not exit on error
Browse files Browse the repository at this point in the history
  • Loading branch information
mstg committed Sep 7, 2021
1 parent 360c4d5 commit 5d8fdcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 12 additions & 6 deletions pkg/data/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"fmt"
"github.com/go-git/go-billy/v5"
"hash"
"io"
Expand All @@ -34,37 +35,42 @@ import (
"path/filepath"
)

func CopyFromFs(from billy.Filesystem, to billy.Filesystem, path string) {
func CopyFromFs(from billy.Filesystem, to billy.Filesystem, path string) error {
read, err := from.ReadDir(path)
if err != nil {
log.Fatalf("could not read dir: %v", err)
return fmt.Errorf("could not read dir: %v", err)
}

for _, fi := range read {
fullPath := filepath.Join(path, fi.Name())

if fi.IsDir() {
_ = to.MkdirAll(fullPath, 0755)
CopyFromFs(from, to, fullPath)
err := CopyFromFs(from, to, fullPath)
if err != nil {
return err
}
} else {
_ = to.Remove(fullPath)

f, err := to.OpenFile(fullPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fi.Mode())
if err != nil {
log.Fatalf("could not open file: %v", err)
return fmt.Errorf("could not open file: %v", err)
}

oldFile, err := from.Open(fullPath)
if err != nil {
log.Fatalf("could not open from file: %v", err)
return fmt.Errorf("could not open from file: %v", err)
}

_, err = io.Copy(f, oldFile)
if err != nil {
log.Fatalf("could not copy from oldFile to new: %v", err)
return fmt.Errorf("could not copy from oldFile to new: %v", err)
}
}
}

return nil
}

func IgnoredContains(a []*IgnoredSource, b string) bool {
Expand Down
5 changes: 4 additions & 1 deletion pkg/srpmproc/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ func ProcessRPM(pd *data.ProcessData) (map[string]string, error) {
return nil, err
}

data.CopyFromFs(md.Worktree.Filesystem, w.Filesystem, ".")
err = data.CopyFromFs(md.Worktree.Filesystem, w.Filesystem, ".")
if err != nil {
return nil, err
}
md.Repo = repo
md.Worktree = w

Expand Down

0 comments on commit 5d8fdcc

Please sign in to comment.