create missing directories recurisvely
authorspf13 <steve.francia@gmail.com>
Fri, 26 Jul 2013 13:22:23 +0000 (09:22 -0400)
committerspf13 <steve.francia@gmail.com>
Fri, 26 Jul 2013 13:22:23 +0000 (09:22 -0400)
hugolib/helpers.go

index ad3c20277dade8dd0483f95ec24a4a2d691b72a3..7e2adc22148dc56c034fb5b055a155e6ada2daca 100644 (file)
@@ -17,12 +17,13 @@ import (
        "bytes"
        "fmt"
        "github.com/kr/pretty"
+       "html/template"
        "os"
+       "path/filepath"
        "reflect"
        "regexp"
        "strconv"
        "strings"
-       "html/template"
        "time"
 )
 
@@ -137,11 +138,25 @@ func exists(path string) (bool, error) {
        return false, err
 }
 
-func mkdirIf(path string) {
+func mkdirIf(path string) error {
        err := os.Mkdir(path, 0777)
-       if err != nil && os.IsNotExist(err) {
-               fmt.Println(err)
+       if err != nil {
+               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 {