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

Function writeExportArchive

script/ghmock/archive.go:60–86  ·  view source on GitHub ↗
(path string, write func(string) error)

Source from the content-addressed store, hash-verified

58}
59
60func writeExportArchive(path string, write func(string) error) (err error) {
61 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
62 return err
63 }
64 file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o600)
65 if errors.Is(err, fs.ErrExist) {
66 return fmt.Errorf("%s already exists; export to a new file", path)
67 }
68 if err != nil {
69 return err
70 }
71 defer func() {
72 err = errors.Join(err, file.Close())
73 if err != nil {
74 err = errors.Join(err, os.Remove(path))
75 }
76 }()
77 dir, err := os.MkdirTemp(filepath.Dir(path), ".ghmock-export-")
78 if err != nil {
79 return err
80 }
81 defer func() { err = errors.Join(err, os.RemoveAll(dir)) }()
82 if err := write(dir); err != nil {
83 return err
84 }
85 return writeTarGzip(file, dir)
86}
87
88func writeTarGzip(w io.Writer, root string) error {
89 root, err := filepath.EvalSymlinks(root)

Callers 1

cmdExportFunction · 0.85

Calls 6

writeTarGzipFunction · 0.85
MkdirAllMethod · 0.80
JoinMethod · 0.80
ErrorfMethod · 0.65
CloseMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected