Return early if walk target is dir
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 59s

This commit is contained in:
Alexandre Bruyant 2024-01-06 21:05:26 +01:00
parent 41cc0cb790
commit 2f3c0ee4e2

21
main.go
View File

@ -73,15 +73,12 @@ func main() {
err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error { err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error {
githubactions.Infof("Reading %v", innerPath) githubactions.Infof("Reading %v", innerPath)
if err != nil { if err != nil {
return err return err
} }
relativeParh := strings.TrimPrefix(innerPath, path) relativeParh := strings.TrimPrefix(innerPath, path)
w, err := mwriter.CreateFormFile("file", relativeParh)
if err != nil {
return err
}
in, err := os.Open(innerPath) in, err := os.Open(innerPath)
if err != nil { if err != nil {
@ -89,8 +86,22 @@ func main() {
} }
defer in.Close() defer in.Close()
pathInfo, err := in.Stat()
if err != nil {
return err
}
if pathInfo.IsDir() {
return nil
}
w, err := mwriter.CreateFormFile("file", relativeParh)
if err != nil {
return err
}
if written, err := io.Copy(w, in); err != nil { if written, err := io.Copy(w, in); err != nil {
return fmt.Errorf("error copying %s (%d bytes written): %v", path, written, err) return fmt.Errorf("error copying %s (%d bytes written): %v", relativeParh, written, err)
} }
if err := mwriter.Close(); err != nil { if err := mwriter.Close(); err != nil {