2019-11-06 14:12:33 +00:00
|
|
|
package io
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-11-17 11:14:22 +00:00
|
|
|
"path/filepath"
|
2019-11-06 14:12:33 +00:00
|
|
|
)
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// MakeDirForFile creates a directory provided in the filePath.
|
2019-11-06 14:12:33 +00:00
|
|
|
func MakeDirForFile(filePath string, creator string) error {
|
|
|
|
fileName := filePath
|
2021-11-17 11:14:22 +00:00
|
|
|
dir := filepath.Dir(fileName)
|
2019-11-06 14:12:33 +00:00
|
|
|
err := os.MkdirAll(dir, os.ModePerm)
|
|
|
|
if err != nil {
|
2020-08-06 16:09:57 +00:00
|
|
|
return fmt.Errorf("could not create dir for %s: %w", creator, err)
|
2019-11-06 14:12:33 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|