@@ -28,7 +28,7 @@ public static function getLatestBitbucketTag(string $name, array $source): array
28
28
logger ()->debug ("finding {$ name } source from bitbucket tag " );
29
29
$ data = json_decode (self ::curlExec (
30
30
url: "https://api.bitbucket.org/2.0/repositories/ {$ source ['repo ' ]}/refs/tags " ,
31
- retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 )
31
+ retry: self :: getRetryTime ( )
32
32
), true );
33
33
$ ver = $ data ['values ' ][0 ]['name ' ];
34
34
if (!$ ver ) {
@@ -38,7 +38,7 @@ public static function getLatestBitbucketTag(string $name, array $source): array
38
38
$ headers = self ::curlExec (
39
39
url: $ url ,
40
40
method: 'HEAD ' ,
41
- retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 )
41
+ retry: self :: getRetryTime ( )
42
42
);
43
43
preg_match ('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im ' , $ headers , $ matches );
44
44
if ($ matches ) {
@@ -66,7 +66,7 @@ public static function getLatestGithubTarball(string $name, array $source, strin
66
66
$ data = json_decode (self ::curlExec (
67
67
url: "https://api.github.com/repos/ {$ source ['repo ' ]}/ {$ type }" ,
68
68
hooks: [[CurlHook::class, 'setupGithubToken ' ]],
69
- retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 )
69
+ retry: self :: getRetryTime ( )
70
70
), true );
71
71
72
72
if (($ source ['prefer-stable ' ] ?? false ) === false ) {
@@ -85,7 +85,7 @@ public static function getLatestGithubTarball(string $name, array $source, strin
85
85
url: $ url ,
86
86
method: 'HEAD ' ,
87
87
hooks: [[CurlHook::class, 'setupGithubToken ' ]],
88
- retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 )
88
+ retry: self :: getRetryTime ( )
89
89
);
90
90
preg_match ('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im ' , $ headers , $ matches );
91
91
if ($ matches ) {
@@ -108,11 +108,11 @@ public static function getLatestGithubTarball(string $name, array $source, strin
108
108
*/
109
109
public static function getLatestGithubRelease (string $ name , array $ source , bool $ match_result = true ): array
110
110
{
111
- logger ()->debug ("finding {$ name } from github releases assests " );
111
+ logger ()->debug ("finding {$ name } from github releases assets " );
112
112
$ data = json_decode (self ::curlExec (
113
113
url: "https://api.github.com/repos/ {$ source ['repo ' ]}/releases " ,
114
114
hooks: [[CurlHook::class, 'setupGithubToken ' ]],
115
- retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 )
115
+ retry: self :: getRetryTime ( )
116
116
), true );
117
117
$ url = null ;
118
118
foreach ($ data as $ release ) {
@@ -149,7 +149,7 @@ public static function getLatestGithubRelease(string $name, array $source, bool
149
149
public static function getFromFileList (string $ name , array $ source ): array
150
150
{
151
151
logger ()->debug ("finding {$ name } source from file list " );
152
- $ page = self ::curlExec ($ source ['url ' ], retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 ));
152
+ $ page = self ::curlExec ($ source ['url ' ], retry: self :: getRetryTime ( ));
153
153
preg_match_all ($ source ['regex ' ], $ page , $ matches );
154
154
if (!$ matches ) {
155
155
throw new DownloaderException ("Failed to get {$ name } version " );
@@ -194,7 +194,7 @@ public static function downloadFile(string $name, string $url, string $filename,
194
194
}
195
195
};
196
196
self ::registerCancelEvent ($ cancel_func );
197
- self ::curlDown (url: $ url , path: FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ filename }" ), retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 ));
197
+ self ::curlDown (url: $ url , path: FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ filename }" ), retry: self :: getRetryTime ( ));
198
198
self ::unregisterCancelEvent ();
199
199
logger ()->debug ("Locking {$ filename }" );
200
200
self ::lockSource ($ name , ['source_type ' => 'archive ' , 'filename ' => $ filename , 'move_path ' => $ move_path , 'lock_as ' => $ lock_as ]);
@@ -347,7 +347,7 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f
347
347
$ pkg ['url ' ],
348
348
$ pkg ['rev ' ],
349
349
$ pkg ['extract ' ] ?? null ,
350
- intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 ),
350
+ self :: getRetryTime ( ),
351
351
SPC_LOCK_PRE_BUILT
352
352
);
353
353
break ;
@@ -451,7 +451,7 @@ public static function downloadSource(string $name, ?array $source = null, bool
451
451
$ source ['url ' ],
452
452
$ source ['rev ' ],
453
453
$ source ['path ' ] ?? null ,
454
- intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 ),
454
+ self :: getRetryTime ( ),
455
455
$ lock_as
456
456
);
457
457
break ;
@@ -567,7 +567,7 @@ public static function curlDown(string $url, string $path, string $method = 'GET
567
567
}
568
568
if ($ retry > 0 ) {
569
569
logger ()->notice ('Retrying curl download ... ' );
570
- self ::curlDown ($ url , $ path , $ method , $ used_headers , retry: intval ( getenv ( ' SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 ) );
570
+ self ::curlDown ($ url , $ path , $ method , $ used_headers , retry: $ retry - 1 );
571
571
return ;
572
572
}
573
573
throw $ e ;
@@ -601,4 +601,9 @@ private static function unregisterCancelEvent(): void
601
601
pcntl_signal (2 , SIG_IGN );
602
602
}
603
603
}
604
+
605
+ private static function getRetryTime (): int
606
+ {
607
+ return intval (getenv ('SPC_RETRY_TIME ' ) ? getenv ('SPC_RETRY_TIME ' ) : 0 );
608
+ }
604
609
}
0 commit comments