Skip to content

Commit 9b9da56

Browse files
committed
Caching
1 parent 7d7a5b7 commit 9b9da56

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

postgresql_embedded/build/bundle.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
use anyhow::Result;
44
use postgresql_archive::configuration::{custom, theseus};
55
use postgresql_archive::repository::github::repository::GitHub;
6-
use postgresql_archive::{VersionReq, matcher, ExactVersion};
6+
use postgresql_archive::{ExactVersion, VersionReq, matcher};
77
use postgresql_archive::{get_archive, repository};
8+
use std::env::home_dir;
89
use std::fs::File;
910
use std::io::Write;
1011
use std::path::PathBuf;
1112
use std::str::FromStr;
1213
use std::{env, fs};
13-
use std::env::home_dir;
1414
use url::Url;
1515

1616
/// Stage the PostgreSQL archive when the `bundled` feature is enabled so that
@@ -54,18 +54,30 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
5454
return Ok(());
5555
}
5656

57-
panic!();
58-
59-
6057
let (asset_version, archive);
6158

62-
// Only works when exact version is specified
63-
if let Some(exact_version) = version_req.exact_version() {
64-
let cached_file_name = home_dir().unwrap_or_else(|| env::current_dir().unwrap_or_default()).join(".theseus")
59+
// Only works when exact version is specified and with the `bundled` feature
60+
// In runtime, the archive seems to be cached
61+
if cfg!(feature = "bundled") && let Some(exact_version) = version_req.exact_version() {
62+
println!("Using existing version: {exact_version:?}");
63+
let ver = exact_version.to_string();
64+
let target_os = if cfg!(target_os = "windows") {
65+
"windows"
66+
} else if cfg!(target_os = "linux") {
67+
"linux"
68+
} else {
69+
panic!("Unsupported target OS: only windows and linux are supported");
70+
};
71+
let cached_file_name = home_dir()
72+
.unwrap_or_else(|| env::current_dir().unwrap_or_default())
73+
.join(".theseus")
6574
.join("postgresql")
66-
.join(format!("postgresql-{}-{}-{}.tar.gz", ver, cfg!(target_os), cfg!(target_arch)));
75+
.join(format!("postgresql-{}-{}.tar.gz", ver, target_os));
6776

68-
println!("Cached file name: {cached_file_name:?} - exists: {}", cached_file_name.exists());
77+
println!(
78+
"Cached file name: {cached_file_name:?} - exists: {}",
79+
cached_file_name.exists()
80+
);
6981
if !cached_file_name.is_file() {
7082
(asset_version, archive) = get_archive(&releases_url, &version_req).await?;
7183
fs::create_dir_all(cached_file_name.parent().unwrap())?;

0 commit comments

Comments
 (0)