2022-01-07 10:55:28 +01:00
|
|
|
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.
|
2022-01-07 10:55:28 +01:00
|
|
|
func CreateDirectoryIfNotExists(dir string) {
|
2022-01-30 00:16:59 +01:00
|
|
|
if _, err := mockOsStat(dir); err == nil {
|
2022-01-07 10:55:28 +01:00
|
|
|
//ignore
|
|
|
|
} else if os.IsNotExist(err) {
|
2022-01-30 00:16:59 +01:00
|
|
|
mockOsMkdirAll(dir, 0755)
|
2022-01-07 10:55:28 +01:00
|
|
|
} else {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|