MCPcopy
hub / github.com/cli/cli / extractFile

Function extractFile

pkg/cmd/copilot/copilot.go:448–462  ·  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

446
447// extractFile creates a file at target with the given mode and copies content from r.
448func extractFile(target string, mode os.FileMode, r io.Reader) (err error) {
449 out, err := os.OpenFile(target, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
450 if err != nil {
451 return fmt.Errorf("failed to create file: %w", err)
452 }
453 defer func() {
454 if cerr := out.Close(); err == nil && cerr != nil {
455 err = fmt.Errorf("failed to close file: %w", cerr)
456 }
457 }()
458 if _, err := io.Copy(out, r); err != nil {
459 return fmt.Errorf("failed to write file: %w", err)
460 }
461 return nil
462}
463
464func removeCopilot(installDir string) error {
465 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