11use crate :: error:: Error :: { DatabaseInitializationError , DatabaseStartError , DatabaseStopError } ;
22use crate :: error:: Result ;
33use crate :: settings:: { BOOTSTRAP_DATABASE , BOOTSTRAP_SUPERUSER , Settings } ;
4+ use postgresql_archive:: extract;
5+ #[ cfg( not( feature = "bundled" ) ) ]
6+ use postgresql_archive:: get_archive;
47use postgresql_archive:: get_version;
58use postgresql_archive:: { ExactVersion , ExactVersionReq } ;
6- use postgresql_archive:: { extract, get_archive} ;
79#[ cfg( feature = "tokio" ) ]
810use postgresql_commands:: AsyncCommandExecutor ;
911use postgresql_commands:: CommandBuilder ;
@@ -179,6 +181,11 @@ impl PostgreSQL {
179181 /// returned.
180182 #[ instrument( skip( self ) ) ]
181183 async fn install ( & mut self ) -> Result < ( ) > {
184+ #[ cfg( feature = "bundled" ) ]
185+ {
186+ self . settings . version = crate :: settings:: ARCHIVE_VERSION . clone ( ) ;
187+ }
188+
182189 debug ! (
183190 "Starting installation process for version {}" ,
184191 self . settings. version
@@ -201,28 +208,21 @@ impl PostgreSQL {
201208
202209 let url = & self . settings . releases_url ;
203210
211+ // When the `bundled` feature is enabled, use the bundled archive instead of downloading it
212+ // from the internet.
204213 #[ cfg( feature = "bundled" ) ]
205- // If the requested version is the same as the version of the bundled archive, use the bundled
206- // archive. This avoids downloading the archive in environments where internet access is
207- // restricted or undesirable.
208- let ( version, bytes) = if * crate :: settings:: ARCHIVE_VERSION == self . settings . version {
214+ let bytes = {
209215 debug ! ( "Using bundled installation archive" ) ;
210- (
211- self . settings . version . clone ( ) ,
212- crate :: settings:: ARCHIVE . to_vec ( ) ,
213- )
214- } else {
215- let ( version, bytes) = get_archive ( url, & self . settings . version ) . await ?;
216- ( version. exact_version_req ( ) ?, bytes)
216+ crate :: settings:: ARCHIVE . to_vec ( )
217217 } ;
218218
219219 #[ cfg( not( feature = "bundled" ) ) ]
220- let ( version , bytes) = {
220+ let bytes = {
221221 let ( version, bytes) = get_archive ( url, & self . settings . version ) . await ?;
222- ( version. exact_version_req ( ) ?, bytes)
222+ self . settings . version = version. exact_version_req ( ) ?;
223+ bytes
223224 } ;
224225
225- self . settings . version = version;
226226 extract ( url, & bytes, & self . settings . installation_dir ) . await ?;
227227
228228 debug ! (
0 commit comments