Skip to content

Commit 857fa2f

Browse files
committed
fix: custom release url not working and compilation failure
1 parent 680e3db commit 857fa2f

File tree

6 files changed

+75
-53
lines changed

6 files changed

+75
-53
lines changed

postgresql_archive/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ serde_json = { workspace = true, optional = true }
3030
sha1 = { workspace = true, optional = true }
3131
sha2 = { workspace = true, optional = true }
3232
tar = { workspace = true }
33-
target-triple = { workspace = true, optional = true }
33+
target-triple = { workspace = true }
3434
tempfile = { workspace = true }
3535
thiserror = { workspace = true }
3636
tokio = { workspace = true, features = ["full"], optional = true }
@@ -70,7 +70,6 @@ rustls = ["reqwest/rustls-tls-native-roots"]
7070
sha1 = ["dep:sha1"]
7171
sha2 = ["dep:sha2"]
7272
theseus = [
73-
"dep:target-triple",
7473
"github",
7574
"sha2",
7675
]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
1+
use semver::Version;
2+
13
#[cfg(feature = "theseus")]
24
pub mod theseus;
35
#[cfg(feature = "zonky")]
46
pub mod zonky;
7+
8+
/// Matcher for PostgreSQL binaries from custom GitHub release repositories
9+
/// following the same pattern as <https://github.com/theseus-rs/postgresql-binaries>
10+
///
11+
/// # Errors
12+
/// * If the asset matcher fails.
13+
pub fn matcher(_url: &str, name: &str, version: &Version) -> crate::Result<bool> {
14+
let target = target_triple::TARGET;
15+
let expected_name = format!("postgresql-{version}-{target}.tar.gz");
16+
Ok(name == expected_name)
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
use crate::Result;
23+
24+
#[test]
25+
fn test_asset_match_success() -> Result<()> {
26+
let url = "";
27+
let version = Version::parse("16.4.0")?;
28+
let target = target_triple::TARGET;
29+
let name = format!("postgresql-{version}-{target}.tar.gz");
30+
31+
assert!(matcher(url, name.as_str(), &version)?, "{}", name);
32+
Ok(())
33+
}
34+
35+
#[test]
36+
fn test_asset_match_errors() -> Result<()> {
37+
let url = "";
38+
let version = Version::parse("16.4.0")?;
39+
let target = target_triple::TARGET;
40+
let names = vec![
41+
format!("foo-{version}-{target}.tar.gz"),
42+
format!("postgresql-{target}.tar.gz"),
43+
format!("postgresql-{version}.tar.gz"),
44+
format!("postgresql-{version}-{target}.tar"),
45+
format!("postgresql-{version}-{target}"),
46+
];
47+
48+
for name in names {
49+
assert!(!matcher(url, name.as_str(), &version)?, "{}", name);
50+
}
51+
Ok(())
52+
}
53+
}

postgresql_archive/src/configuration/theseus/matcher.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
mod extractor;
2-
mod matcher;
32

43
pub const URL: &str = "https://github.com/theseus-rs/postgresql-binaries";
54

65
pub use extractor::extract;
7-
pub use matcher::matcher;

postgresql_archive/src/matcher/registry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::Error::{PoisonedLock, UnsupportedMatcher};
22
use crate::Result;
3+
use crate::configuration::matcher;
34
#[cfg(feature = "theseus")]
45
use crate::configuration::theseus;
56
#[cfg(feature = "zonky")]
@@ -66,7 +67,7 @@ impl Default for MatchersRegistry {
6667
fn default() -> Self {
6768
let mut registry = Self::new();
6869
#[cfg(feature = "theseus")]
69-
registry.register(|url| Ok(url == theseus::URL), theseus::matcher);
70+
registry.register(|url| Ok(url == theseus::URL), matcher);
7071
#[cfg(feature = "zonky")]
7172
registry.register(|url| Ok(url == zonky::URL), zonky::matcher);
7273
registry

postgresql_embedded/build/bundle.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
#![allow(dead_code)]
22

33
use anyhow::Result;
4-
use postgresql_archive::VersionReq;
54
use postgresql_archive::repository::github::repository::GitHub;
5+
use postgresql_archive::{VersionReq, matcher};
66
use postgresql_archive::{get_archive, repository};
77
use std::fs::File;
88
use std::io::Write;
9+
use std::ops::Deref;
910
use std::path::PathBuf;
1011
use std::str::FromStr;
12+
use std::sync::{Arc, LazyLock, Mutex};
1113
use std::{env, fs};
1214
use url::Url;
1315

16+
static CUSTOM_REPO_URL: LazyLock<Arc<Mutex<String>>> =
17+
LazyLock::new(|| Arc::new(Mutex::new(String::new())));
18+
1419
/// Stage the PostgreSQL archive when the `bundled` feature is enabled so that
1520
/// it can be included in the final binary. This is useful for creating a
1621
/// self-contained binary that does not require the PostgreSQL archive to be
@@ -26,6 +31,10 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
2631
let version_req = VersionReq::from_str(postgres_version_req.as_str())?;
2732
println!("PostgreSQL version: {postgres_version_req}");
2833
println!("Target: {}", target_triple::TARGET);
34+
{
35+
let mut custom_repo_url = CUSTOM_REPO_URL.lock().unwrap();
36+
custom_repo_url.push_str(&releases_url);
37+
}
2938

3039
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
3140
println!("OUT_DIR: {:?}", out_dir);
@@ -40,6 +49,8 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
4049
return Ok(());
4150
}
4251

52+
// let str = releases_url.clone();
53+
// let s = str.leak();
4354
register_github_repository()?;
4455
let (asset_version, archive) = get_archive(&releases_url, &version_req).await?;
4556

@@ -61,5 +72,16 @@ fn register_github_repository() -> Result<()> {
6172
},
6273
Box::new(GitHub::new),
6374
)?;
75+
76+
matcher::registry::register(
77+
|url| {
78+
CUSTOM_REPO_URL
79+
.lock()
80+
.map_err(|err| postgresql_archive::Error::PoisonedLock(err.to_string()))
81+
.map(|custom_repo_url| url == custom_repo_url.deref())
82+
},
83+
postgresql_archive::configuration::matcher,
84+
)?;
85+
6486
Ok(())
6587
}

0 commit comments

Comments
 (0)