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

Function prepareExportDir

script/ghmock/export.go:149–160  ·  view source on GitHub ↗

prepareExportDir creates dir, or checks that it's empty, so an export never mixes with other files.

(dir string)

Source from the content-addressed store, hash-verified

147// prepareExportDir creates dir, or checks that it's empty, so an export never
148// mixes with other files.
149func prepareExportDir(dir string) error {
150 entries, err := os.ReadDir(dir)
151 switch {
152 case errors.Is(err, fs.ErrNotExist):
153 return os.MkdirAll(dir, 0o755)
154 case err != nil:
155 return err
156 case len(entries) > 0:
157 return fmt.Errorf("%s isn't empty; export to a new folder", dir)
158 }
159 return nil
160}
161
162func writeFile(path string, write func(io.Writer) error) error {
163 f, err := os.Create(path)

Callers 1

writeExportDirFunction · 0.85

Calls 2

MkdirAllMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected