backive/utils.go

21 lines
427 B
Go
Raw Normal View History

package backive
import (
"log"
"os"
)
2022-01-30 00:16:59 +01:00
var mockOsStat = os.Stat
var mockOsMkdirAll = os.MkdirAll
2022-01-07 11:17:12 +01:00
// CreateDirectoryIfNotExists Checks for a directory string and creates the directory if it does not exist, must be a absolute path.
func CreateDirectoryIfNotExists(dir string) {
2022-01-30 00:16:59 +01:00
if _, err := mockOsStat(dir); err == nil {
//ignore
} else if os.IsNotExist(err) {
2022-01-30 00:16:59 +01:00
mockOsMkdirAll(dir, 0755)
} else {
log.Fatal(err)
}
}