mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-29 07:03:48 +03:00
import: No need to error for no matches if using glob pattern
This commit is contained in:
parent
bbf954cbf2
commit
d60a26ae30
2 changed files with 9 additions and 1 deletions
|
@ -2,6 +2,7 @@ package caddyfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -237,7 +238,11 @@ func (p *parser) doImport() error {
|
||||||
return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
|
return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
|
||||||
}
|
}
|
||||||
if len(matches) == 0 {
|
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)
|
// splice out the import directive and its argument (2 tokens total)
|
||||||
|
|
|
@ -388,6 +388,9 @@ func TestParseAll(t *testing.T) {
|
||||||
{"glob1.host0"},
|
{"glob1.host0"},
|
||||||
{"glob2.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)
|
p := testParser(test.input)
|
||||||
blocks, err := p.parseAll()
|
blocks, err := p.parseAll()
|
||||||
|
|
Loading…
Reference in a new issue