@@ -123,7 +123,7 @@ func (d *downloader) GetByLabel(label string) *TemplateInfo {
123123 return nil
124124}
125125
126- func (d * downloader ) readTemplatesConfig () ([]TemplateInfo , error ) {
126+ func (d * downloader ) readTemplatesConfig (client GetterClient , retryCount int ) ([]TemplateInfo , error ) {
127127 file , err := os .Open (d .configPath )
128128 if err != nil {
129129 return nil , err
@@ -135,6 +135,24 @@ func (d *downloader) readTemplatesConfig() ([]TemplateInfo, error) {
135135 repo := repository {}
136136
137137 if err := decoder .Decode (& repo ); err != nil {
138+ // if an error occurs while decoding the yaml file, delete the file and try again based on the retry count
139+ if retryCount > 0 {
140+ // close the file before deleting it
141+ file .Close ()
142+
143+ err = os .Remove (d .configPath )
144+ if err != nil {
145+ return nil , errors .WithMessage (err , "repository file " + d .configPath )
146+ }
147+
148+ err = client .Get ()
149+ if err != nil {
150+ return nil , errors .WithMessage (err , "repository file " + d .configPath )
151+ }
152+
153+ return d .readTemplatesConfig (client , retryCount - 1 )
154+ }
155+
138156 return nil , errors .WithMessage (err , "repository file " + d .configPath )
139157 }
140158
@@ -166,7 +184,7 @@ func (d *downloader) repository() error {
166184 return err
167185 }
168186
169- list , err := d .readTemplatesConfig ()
187+ list , err := d .readTemplatesConfig (client , 1 )
170188 if err != nil {
171189 return err
172190 }
0 commit comments