io: move common function and add unit tests for it

This commit is contained in:
Vsevolod Brekelov 2019-11-06 17:12:33 +03:00
parent 11ce73af28
commit d799c98cfe
4 changed files with 61 additions and 17 deletions

18
pkg/io/fileWriter.go Normal file
View file

@ -0,0 +1,18 @@
package io
import (
"fmt"
"os"
"path"
)
// MakeDirForFile creates directory provided in filePath.
func MakeDirForFile(filePath string, creator string) error {
fileName := filePath
dir := path.Dir(fileName)
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
return fmt.Errorf("could not create dir for %s: %v", creator, err)
}
return nil
}