-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix finding binaries in the PKGX_PANTRY_DIR #1253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| mod main; | ||
| mod sync; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| use libpkgx::config::Config; | ||
| use libpkgx::sync; | ||
| use rusqlite::Connection; | ||
| use std::sync::Mutex; | ||
| use tempfile::TempDir; | ||
|
|
||
| // serialize tests that mutate PKGX_PANTRY_DIR | ||
| static ENV_MUTEX: Mutex<()> = Mutex::new(()); | ||
|
|
||
| fn test_config(pantry_dir: &std::path::Path, db_file: &std::path::Path) -> Config { | ||
| Config { | ||
| pantry_dir: pantry_dir.to_path_buf(), | ||
| pantry_db_file: db_file.to_path_buf(), | ||
| dist_url: "http://localhost:0".to_string(), | ||
| pkgx_dir: pantry_dir.to_path_buf(), | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_update_with_pantry_dir_rebuilds_db_when_projects_exists() { | ||
| let _lock = ENV_MUTEX.lock().unwrap(); | ||
| let tmp = TempDir::new().unwrap(); | ||
| let pantry_dir = tmp.path().join("pantry"); | ||
| std::fs::create_dir_all(pantry_dir.join("projects")).unwrap(); | ||
| let db_file = tmp.path().join("pantry.2.db"); | ||
|
|
||
| let config = test_config(&pantry_dir, &db_file); | ||
| let mut conn = Connection::open(&db_file).unwrap(); | ||
|
|
||
| std::env::set_var("PKGX_PANTRY_DIR", &pantry_dir); | ||
| let result = sync::update(&config, &mut conn).await; | ||
| std::env::remove_var("PKGX_PANTRY_DIR"); | ||
|
|
||
| assert!( | ||
| result.is_ok(), | ||
| "update should succeed when projects/ exists" | ||
| ); | ||
jhheider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_update_with_pantry_dir_errors_when_projects_missing() { | ||
| let _lock = ENV_MUTEX.lock().unwrap(); | ||
| let tmp = TempDir::new().unwrap(); | ||
| let pantry_dir = tmp.path().join("pantry"); | ||
| std::fs::create_dir_all(&pantry_dir).unwrap(); | ||
| let db_file = tmp.path().join("pantry.2.db"); | ||
|
|
||
| let config = test_config(&pantry_dir, &db_file); | ||
| let mut conn = Connection::open(&db_file).unwrap(); | ||
|
|
||
| std::env::set_var("PKGX_PANTRY_DIR", &pantry_dir); | ||
| let result = sync::update(&config, &mut conn).await; | ||
| std::env::remove_var("PKGX_PANTRY_DIR"); | ||
jhheider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assert!( | ||
| result.is_err(), | ||
| "update should fail when projects/ is missing" | ||
| ); | ||
| let err = result.unwrap_err().to_string(); | ||
| assert!( | ||
| err.contains("missing projects/"), | ||
| "error should mention missing projects/, got: {err}" | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,16 @@ pub async fn ensure(config: &Config, conn: &mut Connection) -> Result<(), Box<dy | |
|
|
||
| pub async fn update(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error>> { | ||
| if std::env::var("PKGX_PANTRY_DIR").is_ok() { | ||
| return Err("PKGX_PANTRY_DIR is set, refusing to update pantry")?; | ||
| if config.pantry_dir.join("projects").is_dir() { | ||
| let lockfile = lock(config)?; | ||
| pantry_db::cache(config, conn)?; | ||
| FileExt::unlock(&lockfile)?; | ||
| return Ok(()); | ||
jhheider marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| return Err( | ||
| "PKGX_PANTRY_DIR is set but does not contain a pantry (missing projects/)", | ||
| )?; | ||
| } | ||
| } | ||
| replace(config, conn).await | ||
|
Comment on lines
34
to
47
|
||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.