From bfe6e7510d9402fca571ad582fd7c3502c23bb47 Mon Sep 17 00:00:00 2001 From: Sauyon Lee Date: Tue, 27 Apr 2021 08:28:56 -0700 Subject: [PATCH] Evaluate symlinks for the dummy file --- extractor/extractor.go | 12 +++++++++--- .../CONSISTENCY/UnexpectedFrontendErrors.expected | 2 +- .../Diagnostics/ExtractionErrors.expected | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/extractor/extractor.go b/extractor/extractor.go index b057465b686..704f80ebbed 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -460,11 +460,17 @@ func (extraction *Extraction) extractError(tw *trap.Writer, err packages.Error, if pos == "" { // extract a dummy file - file, e = filepath.Abs(filepath.Join(".", "-")) + wd, e := os.Getwd() if e != nil { - file = filepath.Join(".", "-") - log.Printf("Warning: failed to get absolute path for for %s", file) + wd = "." + log.Printf("Warning: failed to get working directory") } + ewd, e := filepath.EvalSymlinks(wd) + if e != nil { + ewd = wd + log.Printf("Warning: failed to evaluate symlinks for %s", wd) + } + file = filepath.Join(ewd, "-") } else { var rawfile string if parts := threePartPos.FindStringSubmatch(pos); parts != nil { diff --git a/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected b/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected index 71e5ed320fb..dfd4a4ff15d 100644 --- a/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected +++ b/ql/test/query-tests/Diagnostics/CONSISTENCY/UnexpectedFrontendErrors.expected @@ -1,3 +1,3 @@ -| ../Diagnostics:0:0:0:0 | malformed import path "github.com/github/codeql-go/ql/test/query-tests/Diagnostics/invalid{": invalid char '{' | +| -:0:0:0:0 | malformed import path "github.com/github/codeql-go/ql/test/query-tests/Diagnostics/invalid{": invalid char '{' | | bad.go:3:1:3:1 | expected 'package', found avvu | | type.go:11:9:11:9 | cannot use v (variable of type V) as T value in argument to takesT | diff --git a/ql/test/query-tests/Diagnostics/ExtractionErrors.expected b/ql/test/query-tests/Diagnostics/ExtractionErrors.expected index 842899c1eef..4154baaaccd 100644 --- a/ql/test/query-tests/Diagnostics/ExtractionErrors.expected +++ b/ql/test/query-tests/Diagnostics/ExtractionErrors.expected @@ -1,2 +1,3 @@ | Extraction failed in query-tests/Diagnostics/type.go with error cannot use v (variable of type V) as T value in argument to takesT | 2 | | Extraction failed with error expected 'package', found avvu | 2 | +| Extraction failed with error malformed import path "github.com/github/codeql-go/ql/test/query-tests/Diagnostics/invalid{": invalid char '{' | 2 |