0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Merge branch 'master' of github.com:pedronasser/caddy

This commit is contained in:
Pedro Nasser 2016-07-14 18:17:05 -03:00
commit ffafb2eca8
3 changed files with 13 additions and 15 deletions

View file

@ -22,7 +22,6 @@ import (
"net" "net"
"os" "os"
"os/exec" "os/exec"
"path"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -399,7 +398,7 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r
inst.caddyfileInput = cdyfile inst.caddyfileInput = cdyfile
sblocks, err := loadServerBlocks(stypeName, path.Base(cdyfile.Path()), bytes.NewReader(cdyfile.Body())) sblocks, err := loadServerBlocks(stypeName, cdyfile.Path(), bytes.NewReader(cdyfile.Body()))
if err != nil { if err != nil {
return err return err
} }

View file

@ -212,14 +212,15 @@ func (p *parser) doImport() error {
// make path relative to Caddyfile rather than current working directory (issue #867) // make path relative to Caddyfile rather than current working directory (issue #867)
// and then use glob to get list of matching filenames // and then use glob to get list of matching filenames
var matches []string absFile, err := filepath.Abs(p.Dispenser.filename)
relImportPattern, err := filepath.Rel(filepath.Dir(p.Dispenser.filename), importPattern) if err != nil {
if err == nil { return p.Errf("Failed to get absolute path of file: %s", p.Dispenser.filename)
matches, err = filepath.Glob(relImportPattern)
} else {
matches, err = filepath.Glob(importPattern)
} }
var matches []string
relImportPattern := filepath.Join(filepath.Dir(absFile), importPattern)
matches, err = filepath.Glob(relImportPattern)
if err != nil { if err != nil {
return p.Errf("Failed to use import pattern %s: %v", importPattern, err) return p.Errf("Failed to use import pattern %s: %v", importPattern, err)
} }

View file

@ -187,7 +187,7 @@ func TestParseOneAndImport(t *testing.T) {
{`localhost {`localhost
dir1 arg1 dir1 arg1
import ../testdata/import_test1.txt`, false, []string{ import testdata/import_test1.txt`, false, []string{
"localhost", "localhost",
}, map[string]int{ }, map[string]int{
"dir1": 2, "dir1": 2,
@ -195,16 +195,16 @@ func TestParseOneAndImport(t *testing.T) {
"dir3": 1, "dir3": 1,
}}, }},
{`import ../testdata/import_test2.txt`, false, []string{ {`import testdata/import_test2.txt`, false, []string{
"host1", "host1",
}, map[string]int{ }, map[string]int{
"dir1": 1, "dir1": 1,
"dir2": 2, "dir2": 2,
}}, }},
{`import ../testdata/import_test1.txt ../testdata/import_test2.txt`, true, []string{}, map[string]int{}}, {`import testdata/import_test1.txt testdata/import_test2.txt`, true, []string{}, map[string]int{}},
{`import ../testdata/not_found.txt`, true, []string{}, map[string]int{}}, {`import testdata/not_found.txt`, true, []string{}, map[string]int{}},
{`""`, false, []string{}, map[string]int{}}, {`""`, false, []string{}, map[string]int{}},
@ -394,8 +394,6 @@ func TestEnvironmentReplacement(t *testing.T) {
func testParser(input string) parser { func testParser(input string) parser {
buf := strings.NewReader(input) buf := strings.NewReader(input)
// use relative path to test that import paths are relative to p := parser{Dispenser: NewDispenser("Caddyfile", buf)}
// the Caddyfile rather than the current working directory (issue #867)
p := parser{Dispenser: NewDispenser("../Test", buf)}
return p return p
} }