6
6
"log"
7
7
"os"
8
8
"path/filepath"
9
+ "strings"
9
10
10
11
"github.com/GitHubSecurityLab/gh-qldb/utils"
11
12
"github.com/spf13/cobra"
@@ -30,23 +31,42 @@ func init() {
30
31
}
31
32
32
33
func 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 )
35
36
if err != nil {
36
37
log .Fatal (err )
37
38
}
38
39
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 )
43
63
if err != nil {
44
64
log .Fatal (err )
45
65
}
46
66
pathList = append (pathList , map [string ]string {
47
67
"commitSha" : commitSha ,
48
68
"committedDate" : committedDate ,
49
- "path" : filepath .Join (dir , filename ),
69
+ "path" : filepath .Join (dir , entryName ),
50
70
})
51
71
}
52
72
if jsonFlag {
0 commit comments