|
3 | 3 | use anyhow::Result; |
4 | 4 | use postgresql_archive::configuration::{custom, theseus}; |
5 | 5 | use postgresql_archive::repository::github::repository::GitHub; |
6 | | -use postgresql_archive::{VersionReq, matcher, ExactVersion}; |
| 6 | +use postgresql_archive::{ExactVersion, VersionReq, matcher}; |
7 | 7 | use postgresql_archive::{get_archive, repository}; |
| 8 | +use std::env::home_dir; |
8 | 9 | use std::fs::File; |
9 | 10 | use std::io::Write; |
10 | 11 | use std::path::PathBuf; |
11 | 12 | use std::str::FromStr; |
12 | 13 | use std::{env, fs}; |
13 | | -use std::env::home_dir; |
14 | 14 | use url::Url; |
15 | 15 |
|
16 | 16 | /// Stage the PostgreSQL archive when the `bundled` feature is enabled so that |
@@ -54,18 +54,30 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> { |
54 | 54 | return Ok(()); |
55 | 55 | } |
56 | 56 |
|
57 | | - panic!(); |
58 | | - |
59 | | - |
60 | 57 | let (asset_version, archive); |
61 | 58 |
|
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") |
65 | 74 | .join("postgresql") |
66 | | - .join(format!("postgresql-{}-{}-{}.tar.gz", ver, cfg!(target_os), cfg!(target_arch))); |
| 75 | + .join(format!("postgresql-{}-{}.tar.gz", ver, target_os)); |
67 | 76 |
|
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 | + ); |
69 | 81 | if !cached_file_name.is_file() { |
70 | 82 | (asset_version, archive) = get_archive(&releases_url, &version_req).await?; |
71 | 83 | fs::create_dir_all(cached_file_name.parent().unwrap())?; |
|
0 commit comments