11package provprofile
22
33import (
4- "errors"
54 "fmt"
65 "path/filepath"
76 "strings"
@@ -13,6 +12,7 @@ import (
1312 "github.com/bitrise-io/go-utils/command"
1413 "github.com/bitrise-io/go-utils/maputil"
1514 "github.com/bitrise-io/go-utils/pathutil"
15+ "github.com/pkg/errors"
1616 "github.com/ryanuber/go-glob"
1717)
1818
@@ -106,6 +106,40 @@ func CreateProvisioningProfileModelFromFile(filePth string) (ProvisioningProfile
106106 return provProfileData , nil
107107}
108108
109+ func walkProvProfiles (ppWalkFn func (provProfile ProvisioningProfileFileInfoModel ) error ) error {
110+ absProvProfileDirPath , err := pathutil .AbsPath (provProfileSystemDirPath )
111+ if err != nil {
112+ return errors .Wrap (err , "Failed to get Absolute path of Provisioning Profiles dir" )
113+ }
114+
115+ pths , err := filepath .Glob (absProvProfileDirPath + "/*.mobileprovision" )
116+ if err != nil {
117+ return errors .Wrap (err , "Failed to perform *.mobileprovision search" )
118+ }
119+
120+ for _ , aPth := range pths {
121+ provProfileData , err := CreateProvisioningProfileModelFromFile (aPth )
122+ if err != nil {
123+ return errors .Wrapf (err , "Failed to read Provisioning Profile infos from file (path: %s)" ,
124+ aPth )
125+ }
126+
127+ if time .Now ().After (provProfileData .ExpirationDate ) {
128+ log .Warnf (colorstring .Yellow (" (!) " )+ "Provisioning Profile %s " + colorstring .Yellow ("expired" )+ " at %s. Skipping." ,
129+ colorstring .Blue (provProfileData .UUID ), colorstring .Blue (provProfileData .ExpirationDate ))
130+ log .Warnf (" If you want to delete this Provisioning Profile you can find it at: %s" ,
131+ colorstring .Yellow (aPth ))
132+ continue
133+ }
134+
135+ if err := ppWalkFn (ProvisioningProfileFileInfoModel {Path : aPth , ProvisioningProfileInfo : provProfileData }); err != nil {
136+ return errors .WithStack (err )
137+ }
138+ }
139+
140+ return nil
141+ }
142+
109143// FindProvProfilesByAppID ...
110144// `appID`` supports "glob", e.g.: *.bundle.id will match any Prov Profile with ".bundle.id"
111145// app ID suffix
@@ -156,11 +190,32 @@ func FindProvProfileByUUID(provProfileUUID string) (ProvisioningProfileFileInfoM
156190
157191 // iOS / .mobileprovision
158192 {
193+ isFound := false
159194 mobileProvPth := filepath .Join (absProvProfileDirPath , provProfileUUID + ".mobileprovision" )
160195 exist , err := pathutil .IsPathExists (mobileProvPth )
161- if ! exist || err != nil {
196+ if err != nil {
162197 log .Debugf ("No mobileprovision file found at: %s | err: %s" , mobileProvPth , err )
198+ } else if ! exist {
199+ log .Debugf ("Not found at path (%s), doing a full search by content ..." , mobileProvPth )
200+ // try by content
201+ err := walkProvProfiles (func (ppf ProvisioningProfileFileInfoModel ) error {
202+ if ppf .ProvisioningProfileInfo .UUID == provProfileUUID {
203+ isFound = true
204+ mobileProvPth = ppf .Path
205+ }
206+ return nil
207+ })
208+ if err != nil {
209+ log .Debugf ("Error during Prov Profile walk: %+v" , errors .WithStack (err ))
210+ }
211+ if ! isFound {
212+ log .Debugf ("Prov Profile not found by UUID (walk)" )
213+ }
163214 } else {
215+ isFound = true
216+ }
217+
218+ if isFound {
164219 provProfileData , err := CreateProvisioningProfileModelFromFile (mobileProvPth )
165220 if err != nil {
166221 return ProvisioningProfileFileInfoModel {},
0 commit comments