@@ -20,8 +20,12 @@ const ProfileTypeMacOs ProfileType = "osx"
2020// ProfileTypeTvOs ...
2121const ProfileTypeTvOs ProfileType = "tvos"
2222
23- // ProvProfileSystemDirPath ...
24- const ProvProfileSystemDirPath = "~/Library/MobileDevice/Provisioning Profiles"
23+ const (
24+ // ProvProfileSystemDirPath ...
25+ ProvProfileSystemDirPath = "~/Library/MobileDevice/Provisioning Profiles"
26+ // ProvProfileModernPath is used by Xcode 16 and later, but the old path is still supported.
27+ ProvProfileModernPath = "~/Library/Developer/Xcode/UserData/Provisioning Profiles"
28+ )
2529
2630// ProvisioningProfileFromContent ...
2731func ProvisioningProfileFromContent (content []byte ) (* pkcs7.PKCS7 , error ) {
@@ -39,18 +43,7 @@ func ProvisioningProfileFromFile(pth string) (*pkcs7.PKCS7, error) {
3943
4044// InstalledProvisioningProfiles ...
4145func InstalledProvisioningProfiles (profileType ProfileType ) ([]* pkcs7.PKCS7 , error ) {
42- ext := ".mobileprovision"
43- if profileType == ProfileTypeMacOs {
44- ext = ".provisionprofile"
45- }
46-
47- absProvProfileDirPath , err := pathutil .AbsPath (ProvProfileSystemDirPath )
48- if err != nil {
49- return nil , err
50- }
51-
52- pattern := filepath .Join (pathutil .EscapeGlobPath (absProvProfileDirPath ), "*" + ext )
53- pths , err := filepath .Glob (pattern )
46+ pths , err := listProfiles (profileType )
5447 if err != nil {
5548 return nil , err
5649 }
@@ -69,42 +62,72 @@ func InstalledProvisioningProfiles(profileType ProfileType) ([]*pkcs7.PKCS7, err
6962// FindProvisioningProfile ...
7063func FindProvisioningProfile (uuid string ) (* pkcs7.PKCS7 , string , error ) {
7164 {
72- iosProvisioningProfileExt := ".mobileprovision"
73- absProvProfileDirPath , err := pathutil .AbsPath (ProvProfileSystemDirPath )
65+ pths , err := listProfiles (ProfileTypeIos )
7466 if err != nil {
7567 return nil , "" , err
7668 }
7769
78- pth := filepath .Join (absProvProfileDirPath , uuid + iosProvisioningProfileExt )
79- if exist , err := pathutil .IsPathExists (pth ); err != nil {
80- return nil , "" , err
81- } else if exist {
82- profile , err := ProvisioningProfileFromFile (pth )
83- if err != nil {
84- return nil , "" , err
70+ profileName := uuid + ".mobileprovision"
71+ for _ , pth := range pths {
72+ if filepath .Base (pth ) == profileName {
73+ profile , err := ProvisioningProfileFromFile (pth )
74+ if err != nil {
75+ return nil , "" , err
76+ }
77+ return profile , pth , nil
8578 }
86- return profile , pth , nil
8779 }
8880 }
8981
9082 {
91- macOsProvisioningProfileExt := ".provisionprofile"
92- absProvProfileDirPath , err := pathutil .AbsPath (ProvProfileSystemDirPath )
83+ pths , err := listProfiles (ProfileTypeMacOs )
9384 if err != nil {
9485 return nil , "" , err
9586 }
9687
97- pth := filepath .Join (absProvProfileDirPath , uuid + macOsProvisioningProfileExt )
98- if exist , err := pathutil .IsPathExists (pth ); err != nil {
99- return nil , "" , err
100- } else if exist {
101- profile , err := ProvisioningProfileFromFile (pth )
102- if err != nil {
103- return nil , "" , err
88+ profileName := uuid + ".provisionprofile"
89+ for _ , pth := range pths {
90+ if filepath .Base (pth ) == profileName {
91+ profile , err := ProvisioningProfileFromFile (pth )
92+ if err != nil {
93+ return nil , "" , err
94+ }
95+ return profile , pth , nil
10496 }
105- return profile , pth , nil
10697 }
10798 }
10899
109100 return nil , "" , nil
110101}
102+
103+ func listProfiles (profileType ProfileType ) ([]string , error ) {
104+ ext := ".mobileprovision"
105+ if profileType == ProfileTypeMacOs {
106+ ext = ".provisionprofile"
107+ }
108+
109+ absProvProfileDirPath , err := pathutil .AbsPath (ProvProfileSystemDirPath )
110+ if err != nil {
111+ return nil , err
112+ }
113+
114+ pattern := filepath .Join (pathutil .EscapeGlobPath (absProvProfileDirPath ), "*" + ext )
115+ pths , err := filepath .Glob (pattern )
116+ if err != nil {
117+ return nil , err
118+ }
119+
120+ absProvProfileModernDirPath , err := pathutil .AbsPath (ProvProfileModernPath )
121+ if err != nil {
122+ return nil , err
123+ }
124+
125+ pattern = filepath .Join (pathutil .EscapeGlobPath (absProvProfileModernDirPath ), "*" + ext )
126+ newPaths , err := filepath .Glob (pattern )
127+ if err != nil {
128+ return nil , err
129+ }
130+
131+ pths = append (pths , newPaths ... )
132+ return pths , nil
133+ }
0 commit comments