diff options
author | WeidiDeng <[email protected]> | 2023-05-26 03:05:00 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2023-05-25 13:05:00 -0600 |
commit | 9cde71552576dcc724eff38dee42879c927b72ec (patch) | |
tree | 5af6bec905fadbc7ef0f9d8be610f7ffe3758682 /caddyconfig/caddyfile/parse.go | |
parent | 942fbb37ec46f1907e57a04c44ca790bd47ed52c (diff) | |
download | caddy-9cde71552576dcc724eff38dee42879c927b72ec.tar.gz caddy-9cde71552576dcc724eff38dee42879c927b72ec.zip |
caddyfile: Track import name instead of modifying filename (#5540)
* Merge branch 'master' into import_file_stack
* remove space in log key
Diffstat (limited to 'caddyconfig/caddyfile/parse.go')
-rw-r--r-- | caddyconfig/caddyfile/parse.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index 5afdc2174..81181a473 100644 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -429,7 +429,7 @@ func (p *parser) doImport(nesting int) error { nodes = matches } - nodeName := p.Token().originalFile() + nodeName := p.File() if p.Token().snippetName != "" { nodeName += fmt.Sprintf(":%s", p.Token().snippetName) } @@ -453,18 +453,18 @@ func (p *parser) doImport(nesting int) error { // golang for range slice return a copy of value // similarly, append also copy value for i, token := range importedTokens { - // set the token's file to refer to import directive line number and snippet name + // update the token's imports to refer to import directive filename, line number and snippet name if there is one if token.snippetName != "" { - token.updateFile(fmt.Sprintf("%s:%d (import %s)", token.File, p.Line(), token.snippetName)) + token.imports = append(token.imports, fmt.Sprintf("%s:%d (import %s)", p.File(), p.Line(), token.snippetName)) } else { - token.updateFile(fmt.Sprintf("%s:%d (import)", token.File, p.Line())) + token.imports = append(token.imports, fmt.Sprintf("%s:%d (import)", p.File(), p.Line())) } // naive way of determine snippets, as snippets definition can only follow name + block // format, won't check for nesting correctness or any other error, that's what parser does. if !maybeSnippet && nesting == 0 { // first of the line - if i == 0 || importedTokens[i-1].originalFile() != token.originalFile() || importedTokens[i-1].Line+importedTokens[i-1].NumLineBreaks() < token.Line { + if i == 0 || importedTokens[i-1].File != token.File || importedTokens[i-1].Line+importedTokens[i-1].NumLineBreaks() < token.Line { index = 0 } else { index++ |