Skip to content

Commit fa534e6

Browse files
author
Rafał Mikrut
committed
Do not download postgres in runtime, when different version is bundled in binary
1 parent fad0458 commit fa534e6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

postgresql_embedded/src/postgresql.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use crate::error::Error::{DatabaseInitializationError, DatabaseStartError, DatabaseStopError};
22
use crate::error::Result;
33
use crate::settings::{BOOTSTRAP_DATABASE, BOOTSTRAP_SUPERUSER, Settings};
4-
use postgresql_archive::get_version;
5-
use postgresql_archive::{ExactVersion, ExactVersionReq};
6-
use postgresql_archive::{extract, get_archive};
4+
use std::fmt::Debug;
5+
6+
use postgresql_archive::{ExactVersion, extract};
7+
#[cfg(not(feature = "bundled"))]
8+
use postgresql_archive::{ExactVersionReq, get_archive, get_version};
79
#[cfg(feature = "tokio")]
810
use postgresql_commands::AsyncCommandExecutor;
911
use postgresql_commands::CommandBuilder;
@@ -186,12 +188,20 @@ impl PostgreSQL {
186188
// If the exact version is not set, determine the latest version and update the version and
187189
// installation directory accordingly. This is an optimization to avoid downloading the
188190
// archive if the latest version is already installed.
191+
#[cfg(not(feature = "bundled"))]
189192
if self.settings.version.exact_version().is_none() {
190193
let version = get_version(&self.settings.releases_url, &self.settings.version).await?;
191194
self.settings.version = version.exact_version_req()?;
192195
self.settings.installation_dir =
193196
self.settings.installation_dir.join(version.to_string());
194197
}
198+
#[cfg(feature = "bundled")]
199+
if self.settings.version.exact_version().is_none() {
200+
panic!(
201+
"Bundled version should always be set to an exact version e.g. \"=15.4.1\", got - {:?}",
202+
self.settings.version
203+
);
204+
}
195205

196206
if self.settings.installation_dir.exists() {
197207
debug!("Installation directory already exists");
@@ -202,17 +212,19 @@ impl PostgreSQL {
202212

203213
#[cfg(feature = "bundled")]
204214
// If the requested version is the same as the version of the bundled archive, use the bundled
205-
// archive. This avoids downloading the archive in environments where internet access is
206-
// restricted or undesirable.
215+
// archive. Otherwise don't download the archive, because user expects the bundled archive to be used not the one from internet.
207216
let (version, bytes) = if *crate::settings::ARCHIVE_VERSION == self.settings.version {
208217
debug!("Using bundled installation archive");
209218
(
210219
self.settings.version.clone(),
211220
crate::settings::ARCHIVE.to_vec(),
212221
)
213222
} else {
214-
let (version, bytes) = get_archive(url, &self.settings.version).await?;
215-
(version.exact_version_req()?, bytes)
223+
panic!(
224+
"Bundled version \n\"{:?}\", settings version - \"{:?}\"",
225+
*crate::settings::ARCHIVE_VERSION,
226+
self.settings.version
227+
);
216228
};
217229

218230
#[cfg(not(feature = "bundled"))]

0 commit comments

Comments
 (0)