Skip to content

Commit

Permalink
Merge pull request SRI-CSL#54 from woodruffw-forks/ww/dedupe-bitcode-…
Browse files Browse the repository at this point in the history
…paths

extractor, utils: dedupe bitcode paths before linking
  • Loading branch information
ianamason authored Jul 23, 2021
2 parents d01ecad + 1ac1afd commit c240a4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ func handleExecutable(ea ExtractionArgs) (success bool) {
sort.Strings(artifactPaths)
}

// Deduplicate any files to link
dedupeStrings(&filesToLink)

// Write manifest
if ea.WriteManifest {
if !writeManifest(ea, filesToLink, artifactPaths) {
Expand Down
14 changes: 14 additions & 0 deletions shared/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,17 @@ func runCmd(cmdExecName string, args []string) (output string, err error) {
output = outb.String()
return
}

// Deduplicate a potentially unsorted list of strings in-place without changing their order
func dedupeStrings(strings *[]string) {
seen := make(map[string]bool)
count := 0
for _, s := range *strings {
if _, exists := seen[s]; !exists {
seen[s] = true
(*strings)[count] = s
count++
}
}
*strings = (*strings)[:count]
}

0 comments on commit c240a4f

Please sign in to comment.