writeFileFromReader writes the contents of r to diskPath, creating parent directories as needed and preserving the executable bit on non-Windows hosts.
(diskPath string, r io.Reader, mode os.FileMode)
| 550 | // writeFileFromReader writes the contents of r to diskPath, creating parent |
| 551 | // directories as needed and preserving the executable bit on non-Windows hosts. |
| 552 | func writeFileFromReader(diskPath string, r io.Reader, mode os.FileMode) error { |
| 553 | if err := os.MkdirAll(filepath.Dir(diskPath), 0o777); err != nil { |
| 554 | return fmt.Errorf("could not create directory: %w", err) |
| 555 | } |
| 556 | outFile, err := os.Create(diskPath) |
| 557 | if err != nil { |
| 558 | return fmt.Errorf("could not create file: %w", err) |
| 559 | } |
| 560 | if _, err := io.Copy(outFile, r); err != nil { |
| 561 | outFile.Close() //nolint:errcheck |
| 562 | return fmt.Errorf("could not write file: %w", err) |
| 563 | } |
| 564 | if err := outFile.Close(); err != nil { |
| 565 | return fmt.Errorf("could not close file: %w", err) |
| 566 | } |
| 567 | if mode.Perm()&0o100 != 0 && runtime.GOOS != "windows" { |
| 568 | if err := makeFileExecutable(diskPath); err != nil { |
| 569 | return err |
| 570 | } |
| 571 | } |
| 572 | return nil |
| 573 | } |
| 574 | |
| 575 | // extractTarGzEntry extracts a single named entry from a gzipped tar archive to |
| 576 | // diskPath and marks it executable. |
no test coverage detected