11#![ allow( dead_code) ]
22
33use anyhow:: Result ;
4- use postgresql_archive:: VersionReq ;
4+ use postgresql_archive:: configuration:: custom;
5+ use postgresql_archive:: matcher:: registry:: SupportsFn ;
56use postgresql_archive:: repository:: github:: repository:: GitHub ;
7+ use postgresql_archive:: { VersionReq , matcher} ;
68use postgresql_archive:: { get_archive, repository} ;
79use std:: fs:: File ;
810use std:: io:: Write ;
911use std:: path:: PathBuf ;
1012use std:: str:: FromStr ;
13+ use std:: sync:: Arc ;
1114use std:: { env, fs} ;
1215use url:: Url ;
1316
@@ -20,7 +23,16 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
2023 let default_releases_url = postgresql_archive:: configuration:: theseus:: URL . to_string ( ) ;
2124 #[ cfg( not( feature = "theseus" ) ) ]
2225 let default_releases_url = String :: new ( ) ;
23- let releases_url = env:: var ( "POSTGRESQL_RELEASES_URL" ) . unwrap_or ( default_releases_url) ;
26+
27+ let releases_url = match env:: var ( "POSTGRESQL_RELEASES_URL" ) {
28+ Ok ( custom_url) => {
29+ if !custom_url. is_empty ( ) {
30+ register_github_repository ( & custom_url) ?;
31+ }
32+ custom_url
33+ }
34+ Err ( _) => default_releases_url,
35+ } ;
2436 println ! ( "PostgreSQL releases URL: {releases_url}" ) ;
2537 let postgres_version_req = env:: var ( "POSTGRESQL_VERSION" ) . unwrap_or ( "*" . to_string ( ) ) ;
2638 let version_req = VersionReq :: from_str ( postgres_version_req. as_str ( ) ) ?;
@@ -40,7 +52,6 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
4052 return Ok ( ( ) ) ;
4153 }
4254
43- register_github_repository ( ) ?;
4455 let ( asset_version, archive) = get_archive ( & releases_url, & version_req) . await ?;
4556
4657 fs:: write ( archive_version_file. clone ( ) , asset_version. to_string ( ) ) ?;
@@ -52,7 +63,7 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
5263 Ok ( ( ) )
5364}
5465
55- fn register_github_repository ( ) -> Result < ( ) > {
66+ fn register_github_repository ( custom_url : & str ) -> Result < ( ) > {
5667 repository:: registry:: register (
5768 |url| {
5869 let parsed_url = Url :: parse ( url) ?;
@@ -61,5 +72,12 @@ fn register_github_repository() -> Result<()> {
6172 } ,
6273 Box :: new ( GitHub :: new) ,
6374 ) ?;
75+
76+ // make custom_url as Send + Sync + 'static
77+ let custom_url = Arc :: new ( custom_url. to_string ( ) ) ;
78+ let supports_fn: SupportsFn = Box :: new ( move |url| Ok ( url == custom_url. as_str ( ) ) ) ;
79+ // register the matcher
80+ matcher:: registry:: register ( supports_fn, custom:: matcher:: matcher) ?;
81+
6482 Ok ( ( ) )
6583}
0 commit comments