extract drop/create dir func

This commit is contained in:
Kirill Zhuravlev 2023-02-15 00:39:11 +01:00 committed by Avelino
parent 494289eb6f
commit e05067733e
No known key found for this signature in database
GPG Key ID: B345B4D52E98180A

24
main.go
View File

@ -58,15 +58,8 @@ func main() {
// FIXME: choose a better name
func renderAll() error {
// Cleanup and re-create output directory
{
if err := os.RemoveAll(outDir); err != nil {
return fmt.Errorf("unable to remove target dir: %w", err)
}
if err := mkdirAll(outDir); err != nil {
return fmt.Errorf("unable to create target dir: %w", err)
}
if err := dropCreateDir(outDir); err != nil {
return fmt.Errorf("unable to drop-create out dir: %w", err)
}
err := renderIndex(readmePath, outIndexFile)
@ -130,6 +123,19 @@ func renderAll() error {
return nil
}
// dropCreateDir drop and create output directory
func dropCreateDir(dir string) error {
if err := os.RemoveAll(dir); err != nil {
return fmt.Errorf("unable to remove dir: %w", err)
}
if err := mkdirAll(dir); err != nil {
return fmt.Errorf("unable to create dir: %w", err)
}
return nil
}
func mkdirAll(path string) error {
_, err := os.Stat(path)
// NOTE: directory is exists