@@ -3,9 +3,7 @@ use crate::command::pg_ctl::Mode::{Start, Stop};
3
3
use crate :: command:: pg_ctl:: PgCtlBuilder ;
4
4
use crate :: command:: pg_ctl:: ShutdownMode :: Fast ;
5
5
use crate :: command:: traits:: { CommandBuilder , CommandExecutor } ;
6
- use crate :: error:: Error :: {
7
- ArchiveNotFound , DatabaseInitializationError , DatabaseStartError , DatabaseStopError ,
8
- } ;
6
+ use crate :: error:: Error :: { DatabaseInitializationError , DatabaseStartError , DatabaseStopError } ;
9
7
use crate :: error:: Result ;
10
8
use crate :: settings:: Settings ;
11
9
use bytes:: Bytes ;
@@ -94,7 +92,7 @@ impl PostgreSQL {
94
92
postgresql
95
93
}
96
94
97
- /// Get the default version used by if not otherwise specified
95
+ /// Get the default version used if not otherwise specified
98
96
pub fn default_version ( ) -> Version {
99
97
if cfg ! ( feature = "bundled" ) {
100
98
* ARCHIVE_VERSION
@@ -168,19 +166,8 @@ impl PostgreSQL {
168
166
/// already exists, the archive will not be extracted. If the archive is not found, an error will be
169
167
/// returned.
170
168
async fn install ( & mut self ) -> Result < ( ) > {
171
- let mut archive_bytes: Option < Bytes > = None ;
172
-
173
169
debug ! ( "Starting installation process for version {}" , self . version) ;
174
170
175
- #[ cfg( feature = "bundled" ) ]
176
- // If the requested version is the same as the version of the bundled archive, use the bundled
177
- // archive. This avoids downloading the archive in environments where internet access is
178
- // restricted or undesirable.
179
- if ARCHIVE_VERSION . deref ( ) == & self . version {
180
- debug ! ( "Using bundled installation archive" ) ;
181
- archive_bytes = Some ( Bytes :: copy_from_slice ( ARCHIVE ) ) ;
182
- }
183
-
184
171
// If the minor and release version are not set, determine the latest version and update the
185
172
// version and installation directory accordingly. This is an optimization to avoid downloading
186
173
// the archive if the latest version is already installed.
@@ -191,35 +178,33 @@ impl PostgreSQL {
191
178
. settings
192
179
. installation_dir
193
180
. join ( self . version . to_string ( ) ) ;
194
-
195
- if self . settings . installation_dir . exists ( ) {
196
- debug ! ( "Installation directory already exists" ) ;
197
- self . update_status ( ) ;
198
- return Ok ( ( ) ) ;
199
- }
200
181
}
201
182
202
- if archive_bytes . is_none ( ) {
203
- let ( version , bytes ) = get_archive ( & self . version ) . await ? ;
204
- self . version = version ;
205
- archive_bytes = Some ( bytes ) ;
183
+ if self . settings . installation_dir . exists ( ) {
184
+ debug ! ( "Installation directory already exists" ) ;
185
+ self . update_status ( ) ;
186
+ return Ok ( ( ) ) ;
206
187
}
207
188
208
- if !self . settings . installation_dir . exists ( ) {
209
- self . status = Status :: Installing ;
210
- create_dir_all ( & self . settings . installation_dir ) ?;
211
-
212
- match archive_bytes {
213
- Some ( bytes) => {
214
- extract ( & bytes, & self . settings . installation_dir ) . await ?;
215
- self . status = Status :: Installed ;
216
- }
217
- None => {
218
- self . update_status ( ) ;
219
- return Err ( ArchiveNotFound ( self . version . to_string ( ) ) ) ;
220
- }
221
- }
222
- }
189
+ #[ cfg( feature = "bundled" ) ]
190
+ // If the requested version is the same as the version of the bundled archive, use the bundled
191
+ // archive. This avoids downloading the archive in environments where internet access is
192
+ // restricted or undesirable.
193
+ let ( version, bytes) = if ARCHIVE_VERSION . deref ( ) == & self . version {
194
+ debug ! ( "Using bundled installation archive" ) ;
195
+ ( self . version , Bytes :: copy_from_slice ( ARCHIVE ) )
196
+ } else {
197
+ get_archive ( & self . version ) . await ?
198
+ } ;
199
+
200
+ #[ cfg( not( feature = "bundled" ) ) ]
201
+ let ( version, bytes) = { get_archive ( & self . version ) . await ? } ;
202
+
203
+ self . version = version;
204
+ self . status = Status :: Installing ;
205
+ create_dir_all ( & self . settings . installation_dir ) ?;
206
+ extract ( & bytes, & self . settings . installation_dir ) . await ?;
207
+ self . status = Status :: Installed ;
223
208
224
209
debug ! (
225
210
"Installed PostgreSQL version {} to {}" ,
0 commit comments