@@ -7,13 +7,13 @@ import (
77 "strings"
88)
99
10- func getInstalledFormulae (cellarRoot , binRoot string ) ([]installedPkg , error ) {
10+ func getInstalledFormulae (cellarRoot , binRoot string ) ([]* installedPkg , error ) {
1111 entries , err := os .ReadDir (cellarRoot )
1212 if err != nil {
1313 return nil , fmt .Errorf ("failed to read Cellar directory: %w" , err )
1414 }
1515
16- var pkgs []installedPkg
16+ var iPkgs []* installedPkg
1717 for _ , entry := range entries {
1818 if ! entry .IsDir () {
1919 continue
@@ -25,15 +25,15 @@ func getInstalledFormulae(cellarRoot, binRoot string) ([]installedPkg, error) {
2525 continue
2626 }
2727
28- pkgs = append (pkgs , installedPkg {
28+ iPkgs = append (iPkgs , & installedPkg {
2929 Name : name ,
3030 Version : version ,
31- ReceiptPath : filepath .Join (cellarRoot , name , version , receiptName ),
3231 VersionPath : filepath .Join (cellarRoot , name , version ),
32+ IsTap : true ,
3333 })
3434 }
3535
36- return pkgs , nil
36+ return iPkgs , nil
3737}
3838
3939func resolveLinkedVersion (pkgName string , cellarRoot string , binRoot string ) (string , error ) {
@@ -67,3 +67,60 @@ func resolveLinkedVersion(pkgName string, cellarRoot string, binRoot string) (st
6767
6868 return parts [len (parts )- 3 ], nil
6969}
70+
71+ func getTapPackageNames (prefix string , pkgType string ) (map [string ]struct {}, error ) {
72+ tapsRoot := filepath .Join (prefix , "Homebrew/Library/Taps" )
73+ result := make (map [string ]struct {})
74+
75+ users , err := os .ReadDir (tapsRoot )
76+ if err != nil {
77+ return nil , err
78+ }
79+
80+ for _ , user := range users {
81+ userPath := filepath .Join (tapsRoot , user .Name ())
82+ repos , err := os .ReadDir (userPath )
83+ if err != nil {
84+ continue
85+ }
86+
87+ for _ , repo := range repos {
88+ if ! repo .IsDir () {
89+ continue
90+ }
91+
92+ repoPath := filepath .Join (userPath , repo .Name ())
93+ var searchDirs []string
94+
95+ switch pkgType {
96+ case typeFormula :
97+ searchDirs = []string {
98+ filepath .Join (repoPath , "Formula" ),
99+ filepath .Join (repoPath , "HomebrewFormula" ),
100+ repoPath ,
101+ }
102+ case typeCask :
103+ searchDirs = []string {filepath .Join (repoPath , "Casks" )}
104+ default :
105+ continue
106+ }
107+
108+ for _ , dir := range searchDirs {
109+ entries , err := os .ReadDir (dir )
110+ if err != nil {
111+ continue
112+ }
113+
114+ for _ , entry := range entries {
115+ if ! entry .IsDir () && strings .HasSuffix (entry .Name (), ".rb" ) {
116+ name := strings .TrimSuffix (entry .Name (), ".rb" )
117+ result [name ] = struct {}{}
118+ }
119+ }
120+ break
121+ }
122+ }
123+ }
124+
125+ return result , nil
126+ }
0 commit comments