Skip to content

Commit 73287c4

Browse files
Merge pull request #195 from nataliejameson/nmj/skip-installation
Allow skipping the installation step during setup
2 parents 1b51df8 + f45614e commit 73287c4

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

postgresql_embedded/src/postgresql.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ impl PostgreSQL {
5555
// conflicts with other versions. This will also facilitate setting the status of the
5656
// server to the correct initial value. If the minor and release version are not set, the
5757
// installation directory will be determined dynamically during the installation process.
58-
if let Some(version) = postgresql.settings.version.exact_version() {
59-
let path = &postgresql.settings.installation_dir;
60-
let version_string = version.to_string();
61-
62-
if !path.ends_with(&version_string) {
63-
postgresql.settings.installation_dir =
64-
postgresql.settings.installation_dir.join(version_string);
58+
if !postgresql.settings.trust_installation_dir {
59+
if let Some(version) = postgresql.settings.version.exact_version() {
60+
let path = &postgresql.settings.installation_dir;
61+
let version_string = version.to_string();
62+
63+
if !path.ends_with(&version_string) {
64+
postgresql.settings.installation_dir =
65+
postgresql.settings.installation_dir.join(version_string);
66+
}
6567
}
6668
}
67-
6869
postgresql
6970
}
7071

@@ -93,6 +94,10 @@ impl PostgreSQL {
9394
/// If it doesn't, it will search all the child directories for the latest version that matches the requirement.
9495
/// If it returns None, we couldn't find a matching installation.
9596
fn installed_dir(&self) -> Option<PathBuf> {
97+
if self.settings.trust_installation_dir {
98+
return Some(self.settings.installation_dir.clone());
99+
}
100+
96101
let path = &self.settings.installation_dir;
97102
let maybe_path_version = path
98103
.file_name()

postgresql_embedded/src/settings.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub struct Settings {
5858
pub timeout: Option<Duration>,
5959
/// Server configuration options
6060
pub configuration: HashMap<String, String>,
61+
/// Skip installation and inferrence of the installation dir. Trust what the user provided.
62+
pub trust_installation_dir: bool,
6163
}
6264

6365
/// Settings implementation
@@ -109,6 +111,7 @@ impl Settings {
109111
temporary: true,
110112
timeout: Some(Duration::from_secs(5)),
111113
configuration: HashMap::new(),
114+
trust_installation_dir: false,
112115
}
113116
}
114117

@@ -190,6 +193,9 @@ impl Settings {
190193
}
191194
};
192195
}
196+
if let Some(trust_installation_dir) = query_parameters.get("trust_installation_dir") {
197+
settings.trust_installation_dir = trust_installation_dir == "true";
198+
}
193199
let configuration_prefix = "configuration.";
194200
for (key, value) in &query_parameters {
195201
if key.starts_with(configuration_prefix) {
@@ -296,10 +302,11 @@ mod tests {
296302
let password_file = "password_file=/tmp/.pgpass";
297303
let data_dir = "data_dir=/tmp/data";
298304
let temporary = "temporary=false";
305+
let trust_installation_dir = "trust_installation_dir=true";
299306
let timeout = "timeout=10";
300307
let configuration = "configuration.max_connections=42";
301308
let url = format!(
302-
"{base_url}?{releases_url}&{version}&{installation_dir}&{password_file}&{data_dir}&{temporary}&{temporary}&{timeout}&{configuration}"
309+
"{base_url}?{releases_url}&{version}&{installation_dir}&{password_file}&{data_dir}&{temporary}&{trust_installation_dir}&{timeout}&{configuration}"
303310
);
304311

305312
let settings = Settings::from_url(url)?;
@@ -314,6 +321,7 @@ mod tests {
314321
assert_eq!(BOOTSTRAP_SUPERUSER, settings.username);
315322
assert_eq!("password", settings.password);
316323
assert!(!settings.temporary);
324+
assert!(settings.trust_installation_dir);
317325
assert_eq!(Some(Duration::from_secs(10)), settings.timeout);
318326
let configuration = HashMap::from([("max_connections".to_string(), "42".to_string())]);
319327
assert_eq!(configuration, settings.configuration);

0 commit comments

Comments
 (0)