Skip to content

Commit f7955db

Browse files
authored
Merge pull request github#15603 from github/mbg/go/fix-file-info-extraction
2 parents b776cbe + 205847d commit f7955db

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

go/extractor/extractor.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ func (extraction *Extraction) extractError(tw *trap.Writer, err packages.Error,
551551
log.Printf("Warning: failed to evaluate symlinks for %s", wd)
552552
}
553553
file = filepath.Join(ewd, "-")
554+
extraction.extractFileInfo(tw, file, true)
554555
} else {
555556
var rawfile string
556557
if parts := threePartPos.FindStringSubmatch(pos); parts != nil {
@@ -585,7 +586,7 @@ func (extraction *Extraction) extractError(tw *trap.Writer, err packages.Error,
585586
file = afile
586587
}
587588

588-
extraction.extractFileInfo(tw, file)
589+
extraction.extractFileInfo(tw, file, false)
589590
}
590591

591592
extraction.Lock.Lock()
@@ -654,7 +655,7 @@ func (extraction *Extraction) extractFile(ast *ast.File, pkg *packages.Package)
654655
return err
655656
}
656657

657-
extraction.extractFileInfo(tw, path)
658+
extraction.extractFileInfo(tw, path, false)
658659

659660
extractScopes(tw, ast, pkg)
660661

@@ -672,7 +673,7 @@ func (extraction *Extraction) extractFile(ast *ast.File, pkg *packages.Package)
672673

673674
// extractFileInfo extracts file-system level information for the given file, populating
674675
// the `files` and `containerparent` tables
675-
func (extraction *Extraction) extractFileInfo(tw *trap.Writer, file string) {
676+
func (extraction *Extraction) extractFileInfo(tw *trap.Writer, file string, isDummy bool) {
676677
// We may visit the same file twice because `extractError` calls this function to describe files containing
677678
// compilation errors. It is also called for user source files being extracted.
678679
extraction.Lock.Lock()
@@ -704,7 +705,9 @@ func (extraction *Extraction) extractFileInfo(tw *trap.Writer, file string) {
704705
dbscheme.HasLocationTable.Emit(tw, lbl, emitLocation(tw, lbl, 0, 0, 0, 0))
705706
extraction.Lock.Lock()
706707
slbl := extraction.StatWriter.Labeler.FileLabelFor(file)
707-
dbscheme.CompilationCompilingFilesTable.Emit(extraction.StatWriter, extraction.Label, extraction.GetFileIdx(file), slbl)
708+
if !isDummy {
709+
dbscheme.CompilationCompilingFilesTable.Emit(extraction.StatWriter, extraction.Label, extraction.GetFileIdx(file), slbl)
710+
}
708711
extraction.Lock.Unlock()
709712
break
710713
}

go/extractor/gomodextractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (extraction *Extraction) extractGoMod(path string) error {
4040
return err
4141
}
4242

43-
extraction.extractFileInfo(tw, path)
43+
extraction.extractFileInfo(tw, path, false)
4444

4545
file, err := os.Open(path)
4646
if err != nil {

go/ql/lib/semmle/go/Files.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class ExtractedOrExternalFile extends Container, Impl::File, Documentable, ExprP
124124
/** A file that has been extracted. */
125125
class File extends ExtractedOrExternalFile {
126126
File() {
127+
not this.getBaseName() = "-" and
127128
// getAChild is specifically for the Go AST and so does not apply to non-go files
128129
// we care about all non-go extracted files, as only go files can have `@file` entries due to requiring a file entry for diagnostic errors
129130
not this.getExtension() = "go"
@@ -141,6 +142,13 @@ class GoFile extends File {
141142
override string getAPrimaryQlClass() { result = "GoFile" }
142143
}
143144

145+
/** A dummy file. */
146+
class DummyFile extends ExtractedOrExternalFile {
147+
DummyFile() { this.getBaseName() = "-" }
148+
149+
override string getAPrimaryQlClass() { result = "DummyFile" }
150+
}
151+
144152
/** An HTML file. */
145153
class HtmlFile extends File {
146154
HtmlFile() { this.getExtension().regexpMatch("x?html?") }

0 commit comments

Comments
 (0)