backive/utils.go

22 lines
481 B
Go
Raw Normal View History

package backive
import (
"os"
)
2022-01-30 00:16:59 +01:00
var mockOsStat = os.Stat
var mockOsMkdirAll = os.MkdirAll
2022-01-31 22:18:21 +01:00
var mockOsIsNotExist = os.IsNotExist
2022-01-30 00:16:59 +01:00
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-31 22:18:21 +01:00
func CreateDirectoryIfNotExists(dir string) error {
2022-01-30 00:16:59 +01:00
if _, err := mockOsStat(dir); err == nil {
//ignore
2022-01-31 22:18:21 +01:00
} else if mockOsIsNotExist(err) {
return mockOsMkdirAll(dir, 0755)
} else {
2022-01-31 22:18:21 +01:00
return err
}
2022-01-31 22:18:21 +01:00
return nil
}