create missing directories recurisvely

This commit is contained in:
spf13 2013-07-26 09:22:23 -04:00
parent dd9a7e6455
commit b2385f062a

View file

@ -17,12 +17,13 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/kr/pretty" "github.com/kr/pretty"
"html/template"
"os" "os"
"path/filepath"
"reflect" "reflect"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"html/template"
"time" "time"
) )
@ -137,11 +138,25 @@ func exists(path string) (bool, error) {
return false, err return false, err
} }
func mkdirIf(path string) { func mkdirIf(path string) error {
err := os.Mkdir(path, 0777) err := os.Mkdir(path, 0777)
if err != nil && os.IsNotExist(err) { if err != nil {
fmt.Println(err) if os.IsExist(err) {
return nil
}
if os.IsNotExist(err) {
parent, _ := filepath.Split(path)
err2 := mkdirIf(parent)
if err2 != nil {
return err2
} else {
return mkdirIf(path)
}
}
return err
} }
return nil
} }
func Urlize(url string) string { func Urlize(url string) string {