summaryrefslogtreecommitdiffhomepage
path: root/config/setup/root.go
blob: 892578b7a1c8059dcf86c6e59f967b8a28076fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package setup

import (
	"log"
	"os"

	"github.com/mholt/caddy/middleware"
)

func Root(c *Controller) (middleware.Middleware, error) {
	for c.Next() {
		if !c.NextArg() {
			return nil, c.ArgErr()
		}
		c.Root = c.Val()
	}

	// Check if root path exists
	_, err := os.Stat(c.Root)
	if err != nil {
		if os.IsNotExist(err) {
			// Allow this, because the folder might appear later.
			// But make sure the user knows!
			log.Printf("Warning: Root path does not exist: %s", c.Root)
		} else {
			return nil, c.Errf("Unable to access root path '%s': %v", c.Root, err)
		}
	}

	return nil, nil
}