MCPcopy Create free account
hub / github.com/cli/cli / extractFile

Function extractFile

pkg/cmd/copilot/copilot.go:454–468  ·  view source on GitHub ↗

extractFile creates a file at target with the given mode and copies content from r.

(target string, mode os.FileMode, r io.Reader)

Source from the content-addressed store, hash-verified

452
453// extractFile creates a file at target with the given mode and copies content from r.
454func extractFile(target string, mode os.FileMode, r io.Reader) (err error) {
455 out, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
456 if err != nil {
457 return fmt.Errorf("failed to create file: %w", err)
458 }
459 defer func() {
460 if cerr := out.Close(); err == nil && cerr != nil {
461 err = fmt.Errorf("failed to close file: %w", cerr)
462 }
463 }()
464 if _, err := io.Copy(out, r); err != nil {
465 return fmt.Errorf("failed to write file: %w", err)
466 }
467 return nil
468}
469
470func removeCopilot(installDir string) error {
471 if _, err := os.Stat(installDir); os.IsNotExist(err) {

Callers 1

extractTarGzFunction · 0.85

Calls 3

ErrorfMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected