66 "log"
77 "os"
88 "path/filepath"
9+ "strings"
910
1011 "github.com/GitHubSecurityLab/gh-qldb/utils"
1112 "github.com/spf13/cobra"
@@ -30,23 +31,42 @@ func init() {
3031}
3132
3233func info (nwo string , language string ) {
33- dir := filepath . Join ( utils .GetPath (nwo ), language )
34- files , err := os .ReadDir (dir )
34+ dir := utils .GetPath (nwo )
35+ entries , err := os .ReadDir (dir )
3536 if err != nil {
3637 log .Fatal (err )
3738 }
3839 var pathList []map [string ]string
39- for _ , f := range files {
40- filename := f .Name ()
41- sha := filename [:len (filename )- len (filepath .Ext (filename ))]
42- commitSha , committedDate , err := utils .GetCommitInfo (nwo , sha )
40+ for _ , e := range entries {
41+ entryName := e .Name ()
42+ var name string
43+ if filepath .Ext (entryName ) == ".zip" {
44+ // remove the .zip extension if it exists
45+ name = entryName [:len (entryName )- len (filepath .Ext (entryName ))]
46+ } else if e .IsDir () {
47+ name = e .Name ()
48+ } else {
49+ continue
50+ }
51+
52+ // split the name by the "-". first element is the language, second is the short commit sha
53+ nameSplit := strings .Split (name , "-" )
54+ if len (nameSplit ) != 2 {
55+ log .Fatal (fmt .Errorf ("invalid database name: %s" , name ))
56+ }
57+ if nameSplit [0 ] != language {
58+ continue
59+ }
60+ shortSha := nameSplit [1 ]
61+
62+ commitSha , committedDate , err := utils .GetCommitInfo2 (nwo , shortSha )
4363 if err != nil {
4464 log .Fatal (err )
4565 }
4666 pathList = append (pathList , map [string ]string {
4767 "commitSha" : commitSha ,
4868 "committedDate" : committedDate ,
49- "path" : filepath .Join (dir , filename ),
69+ "path" : filepath .Join (dir , entryName ),
5070 })
5171 }
5272 if jsonFlag {
0 commit comments