summaryrefslogtreecommitdiffhomepage
path: root/caddyfile
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2016-08-17 17:03:21 -0600
committerMatthew Holt <[email protected]>2016-08-17 17:03:21 -0600
commit8b8afd72d75df6ca2d8c67df72826aaa09bf7422 (patch)
tree6ec012bc270ac1e119b36401f6e913b164cb0023 /caddyfile
parentc5524b0babddb1ee2ac22293c24a00e0ddb8011e (diff)
downloadcaddy-8b8afd72d75df6ca2d8c67df72826aaa09bf7422.tar.gz
caddy-8b8afd72d75df6ca2d8c67df72826aaa09bf7422.zip
Support env vars in import; make sure it's a file
Diffstat (limited to 'caddyfile')
-rw-r--r--caddyfile/parse.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/caddyfile/parse.go b/caddyfile/parse.go
index d3f65f4a2..92431fc8d 100644
--- a/caddyfile/parse.go
+++ b/caddyfile/parse.go
@@ -201,11 +201,14 @@ func (p *parser) directives() error {
// other words, call Next() to access the first token that was
// imported.
func (p *parser) doImport() error {
- // syntax check
+ // syntax checks
if !p.NextArg() {
return p.ArgErr()
}
- importPattern := p.Val()
+ importPattern := replaceEnvVars(p.Val())
+ if importPattern == "" {
+ return p.Err("Import requires a non-empty filepath")
+ }
if p.NextArg() {
return p.Err("Import takes only one argument (glob pattern or file)")
}
@@ -284,6 +287,13 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
return nil, p.Errf("Could not import %s: %v", importFile, err)
}
defer file.Close()
+
+ if info, err := file.Stat(); err != nil {
+ return nil, p.Errf("Could not import %s: %v", importFile, err)
+ } else if info.IsDir() {
+ return nil, p.Errf("Could not import %s: is a directory", importFile)
+ }
+
importedTokens := allTokens(file)
// Tack the filename onto these tokens so errors show the imported file's name