diff --git a/codeql-extractor.yml b/codeql-extractor.yml index b258b193f56..e4da61ac7af 100644 --- a/codeql-extractor.yml +++ b/codeql-extractor.yml @@ -6,6 +6,8 @@ pull_request_triggers: - "**/glide.yaml" - "**/Gopkg.toml" column_kind: "utf8" +extra_env_vars: + CODEQL_REDUCE_FILES_FOLDERS_RELATIONS: "true" file_types: - name: go display_name: Go diff --git a/codeql-tools/pre-finalize.cmd b/codeql-tools/pre-finalize.cmd index 4abac249933..f8909ea54ef 100644 --- a/codeql-tools/pre-finalize.cmd +++ b/codeql-tools/pre-finalize.cmd @@ -1,6 +1,8 @@ @echo off SETLOCAL EnableDelayedExpansion +SET CODEQL_REDUCE_FILES_FOLDERS_RELATIONS=true + if NOT "%CODEQL_EXTRACTOR_GO_EXTRACT_HTML%"=="no" ( type NUL && "%CODEQL_DIST%/codeql.exe" database index-files ^ --working-dir=. ^ diff --git a/codeql-tools/pre-finalize.sh b/codeql-tools/pre-finalize.sh index 3a8b31c70a0..6151f552698 100755 --- a/codeql-tools/pre-finalize.sh +++ b/codeql-tools/pre-finalize.sh @@ -3,7 +3,7 @@ set -eu if [ "${CODEQL_EXTRACTOR_GO_EXTRACT_HTML:-yes}" != "no" ]; then - "$CODEQL_DIST/codeql" database index-files \ + CODEQL_REDUCE_FILES_FOLDERS_RELATIONS=true "$CODEQL_DIST/codeql" database index-files \ --working-dir=. \ --include-extension=.htm \ --include-extension=.html \ diff --git a/extractor/dbscheme/tables.go b/extractor/dbscheme/tables.go index 0a968fd8ecd..8da7312dfb8 100644 --- a/extractor/dbscheme/tables.go +++ b/extractor/dbscheme/tables.go @@ -896,16 +896,12 @@ var NumlinesTable = NewTable("numlines", var FilesTable = NewTable("files", EntityColumn(FileType, "id").Key(), StringColumn("name"), - StringColumn("simple"), - StringColumn("ext"), - IntColumn("fromSource"), ) // FoldersTable is the table defining folder entities var FoldersTable = NewTable("folders", EntityColumn(FolderType, "id").Key(), StringColumn("name"), - StringColumn("simple"), ) // ContainerParentTable is the table defining the parent-child relation among container entities diff --git a/extractor/extractor.go b/extractor/extractor.go index 2c625ef00a0..4208a788d02 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -590,15 +590,6 @@ func (extraction *Extraction) extractFile(ast *ast.File, pkg *packages.Package) return nil } -// stemAndExt splits a given file name into its stem (the part before the last '.') -// and extension (the part after the last '.') -func stemAndExt(base string) (string, string) { - if i := strings.LastIndexByte(base, '.'); i >= 0 { - return base[:i], base[i+1:] - } - return base, "" -} - // extractFileInfo extracts file-system level information for the given file, populating // the `files` and `containerparent` tables func (extraction *Extraction) extractFileInfo(tw *trap.Writer, file string) { @@ -627,9 +618,8 @@ func (extraction *Extraction) extractFileInfo(tw *trap.Writer, file string) { path = parentPath + "/" + component } if i == len(components)-1 { - stem, ext := stemAndExt(component) lbl := tw.Labeler.FileLabelFor(file) - dbscheme.FilesTable.Emit(tw, lbl, path, stem, ext, 0) + dbscheme.FilesTable.Emit(tw, lbl, path) dbscheme.ContainerParentTable.Emit(tw, parentLbl, lbl) dbscheme.HasLocationTable.Emit(tw, lbl, emitLocation(tw, lbl, 0, 0, 0, 0)) extraction.Lock.Lock() @@ -639,7 +629,7 @@ func (extraction *Extraction) extractFileInfo(tw *trap.Writer, file string) { break } lbl := tw.Labeler.GlobalID(util.EscapeTrapSpecialChars(path) + ";folder") - dbscheme.FoldersTable.Emit(tw, lbl, path, component) + dbscheme.FoldersTable.Emit(tw, lbl, path) if i > 0 { dbscheme.ContainerParentTable.Emit(tw, parentLbl, lbl) } diff --git a/ql/src/go.dbscheme b/ql/src/go.dbscheme index b37faf5d62c..2842941c6f9 100644 --- a/ql/src/go.dbscheme +++ b/ql/src/go.dbscheme @@ -133,9 +133,9 @@ locations_default(unique int id: @location_default, int file: @file ref, int beg numlines(int element_id: @sourceline ref, int num_lines: int ref, int num_code: int ref, int num_comment: int ref); -files(unique int id: @file, string name: string ref, string simple: string ref, string ext: string ref, int fromSource: int ref); +files(unique int id: @file, string name: string ref); -folders(unique int id: @folder, string name: string ref, string simple: string ref); +folders(unique int id: @folder, string name: string ref); containerparent(int parent: @container ref, unique int child: @container ref); diff --git a/ql/src/go.dbscheme.stats b/ql/src/go.dbscheme.stats index 4a1886f84c2..b18e8556fb2 100644 --- a/ql/src/go.dbscheme.stats +++ b/ql/src/go.dbscheme.stats @@ -8175,18 +8175,6 @@ name 529 - - simple - 373 - - - ext - 3 - - - fromSource - 1 - @@ -8205,54 +8193,6 @@ - - id - simple - - - 12 - - - 1 - 2 - 529 - - - - - - - id - ext - - - 12 - - - 1 - 2 - 529 - - - - - - - id - fromSource - - - 12 - - - 1 - 2 - 529 - - - - - name id @@ -8269,301 +8209,6 @@ - - name - simple - - - 12 - - - 1 - 2 - 529 - - - - - - - name - ext - - - 12 - - - 1 - 2 - 529 - - - - - - - name - fromSource - - - 12 - - - 1 - 2 - 529 - - - - - - - simple - id - - - 12 - - - 1 - 2 - 301 - - - 2 - 3 - 47 - - - 3 - 22 - 25 - - - - - - - simple - name - - - 12 - - - 1 - 2 - 301 - - - 2 - 3 - 47 - - - 3 - 22 - 25 - - - - - - - simple - ext - - - 12 - - - 1 - 2 - 368 - - - 2 - 3 - 5 - - - - - - - simple - fromSource - - - 12 - - - 1 - 2 - 373 - - - - - - - ext - id - - - 12 - - - 1 - 2 - 1 - - - 14 - 15 - 1 - - - 514 - 515 - 1 - - - - - - - ext - name - - - 12 - - - 1 - 2 - 1 - - - 14 - 15 - 1 - - - 514 - 515 - 1 - - - - - - - ext - simple - - - 12 - - - 1 - 2 - 1 - - - 14 - 15 - 1 - - - 363 - 364 - 1 - - - - - - - ext - fromSource - - - 12 - - - 1 - 2 - 3 - - - - - - - fromSource - id - - - 12 - - - 529 - 530 - 1 - - - - - - - fromSource - name - - - 12 - - - 529 - 530 - 1 - - - - - - - fromSource - simple - - - 12 - - - 373 - 374 - 1 - - - - - - - fromSource - ext - - - 12 - - - 3 - 4 - 1 - - - - - @@ -8578,10 +8223,6 @@ name 210 - - simple - 178 - @@ -8600,22 +8241,6 @@ - - id - simple - - - 12 - - - 1 - 2 - 210 - - - - - name id @@ -8632,74 +8257,6 @@ - - name - simple - - - 12 - - - 1 - 2 - 210 - - - - - - - simple - id - - - 12 - - - 1 - 2 - 157 - - - 2 - 3 - 18 - - - 3 - 10 - 3 - - - - - - - simple - name - - - 12 - - - 1 - 2 - 157 - - - 2 - 3 - 18 - - - 3 - 10 - 3 - - - - - diff --git a/ql/src/semmle/go/Files.qll b/ql/src/semmle/go/Files.qll index 92981b74711..28cb395beb3 100644 --- a/ql/src/semmle/go/Files.qll +++ b/ql/src/semmle/go/Files.qll @@ -155,7 +155,7 @@ abstract class Container extends @container { /** A folder. */ class Folder extends Container, @folder { - override string getAbsolutePath() { folders(this, result, _) } + override string getAbsolutePath() { folders(this, result) } /** Gets the file or subfolder in this folder that has the given `name`, if any. */ Container getChildContainer(string name) { @@ -182,7 +182,7 @@ class ExtractedOrExternalFile extends Container, @file, Documentable, ExprParent DeclParent, ScopeNode { override Location getLocation() { has_location(this, result) } - override string getAbsolutePath() { files(this, result, _, _, _) } + override string getAbsolutePath() { files(this, result) } /** Gets the number of lines in this file. */ int getNumberOfLines() { numlines(this, result, _, _) }