From d60a26ae30d7e7ca788dcf783a82af1b3a082dd8 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 22 Sep 2016 11:07:37 -0600 Subject: [PATCH] import: No need to error for no matches if using glob pattern --- caddyfile/parse.go | 7 ++++++- caddyfile/parse_test.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/caddyfile/parse.go b/caddyfile/parse.go index be44fc8a8..fab3a8e84 100644 --- a/caddyfile/parse.go +++ b/caddyfile/parse.go @@ -2,6 +2,7 @@ package caddyfile import ( "io" + "log" "os" "path/filepath" "strings" @@ -237,7 +238,11 @@ func (p *parser) doImport() error { return p.Errf("Failed to use import pattern %s: %v", importPattern, err) } if len(matches) == 0 { - return p.Errf("No files matching import pattern %s", importPattern) + if strings.Contains(globPattern, "*") { + log.Printf("[WARNING] No files matching import pattern: %s", importPattern) + } else { + return p.Errf("File to import not found: %s", importPattern) + } } // splice out the import directive and its argument (2 tokens total) diff --git a/caddyfile/parse_test.go b/caddyfile/parse_test.go index f7d021a33..ad7cfa983 100644 --- a/caddyfile/parse_test.go +++ b/caddyfile/parse_test.go @@ -388,6 +388,9 @@ func TestParseAll(t *testing.T) { {"glob1.host0"}, {"glob2.host0"}, }}, + + {`import notfound/*`, false, [][]string{}}, // glob needn't error with no matches + {`import notfound/file.conf`, true, [][]string{}}, // but a specific file should } { p := testParser(test.input) blocks, err := p.parseAll()