diff --git a/Cargo.lock b/Cargo.lock index 925641c9..14bc6e30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3573,7 +3573,7 @@ dependencies = [ [[package]] name = "pyo-agent" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "axum", @@ -3604,7 +3604,7 @@ dependencies = [ [[package]] name = "pyo-api" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "argon2 0.6.0", @@ -3660,7 +3660,7 @@ dependencies = [ [[package]] name = "pyo-builder" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "base64 0.23.1", @@ -3681,7 +3681,7 @@ dependencies = [ [[package]] name = "pyo-cli" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "clap", @@ -3708,7 +3708,7 @@ dependencies = [ [[package]] name = "pyo-db-controller" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "base64 0.23.1", @@ -3730,7 +3730,7 @@ dependencies = [ [[package]] name = "pyo-envd" -version = "0.5.0" +version = "0.5.1" dependencies = [ "libc", "pyo-proto", @@ -3739,7 +3739,7 @@ dependencies = [ [[package]] name = "pyo-flows" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "libc", @@ -3753,7 +3753,7 @@ dependencies = [ [[package]] name = "pyo-kv" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "axum", @@ -3770,7 +3770,7 @@ dependencies = [ [[package]] name = "pyo-proto" -version = "0.5.0" +version = "0.5.1" dependencies = [ "base64 0.23.1", "jiff", @@ -3788,7 +3788,7 @@ dependencies = [ [[package]] name = "pyo-resp" -version = "0.5.0" +version = "0.5.1" dependencies = [ "futures", "socket2", @@ -3797,7 +3797,7 @@ dependencies = [ [[package]] name = "pyo-sandbox" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "axum", @@ -3827,7 +3827,7 @@ dependencies = [ [[package]] name = "pyo-static" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "axum", diff --git a/Cargo.toml b/Cargo.toml index d8e716ca..f80e30a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/pyo-proto", "crates/pyo-api", "crates/pyo-agent", "crates/pyo-builder", "crates/pyo-cli", "crates/pyo-flows", "crates/pyo-resp", "crates/pyo-kv", "crates/pyo-db-controller", "crates/pyo-static", "crates/pyo-envd", "crates/pyo-sandbox"] [workspace.package] -version = "0.5.0" +version = "0.5.1" edition = "2024" license = "Apache-2.0" publish = false diff --git a/crates/pyo-agent/Cargo.toml b/crates/pyo-agent/Cargo.toml index 542309a6..e29acd77 100644 --- a/crates/pyo-agent/Cargo.toml +++ b/crates/pyo-agent/Cargo.toml @@ -7,7 +7,7 @@ publish.workspace = true [dependencies] anyhow = "1.0.104" -pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["command-signing"] } +pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["command-signing"] } futures = "0.3.34" axum = { version = "0.8.9", default-features = false, features = ["http1", "tokio"] } http = "1.5.0" diff --git a/crates/pyo-api/Cargo.toml b/crates/pyo-api/Cargo.toml index 85eb9200..82673cb1 100644 --- a/crates/pyo-api/Cargo.toml +++ b/crates/pyo-api/Cargo.toml @@ -12,7 +12,7 @@ axum = { version = "0.8.9", features = ["ws"] } axum-extra = { version = "0.12.6", features = ["cookie", "typed-header"] } base64 = "0.23.1" cookie = "0.18" -pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["openapi", "sandbox-token", "command-signing", "agent-ca"] } +pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["openapi", "sandbox-token", "command-signing", "agent-ca"] } hex = "0.4.3" hmac = "0.13.0" hyper = { version = "1.12.0", features = ["client", "http1"] } diff --git a/crates/pyo-builder/Cargo.toml b/crates/pyo-builder/Cargo.toml index f0110b52..7f403f30 100644 --- a/crates/pyo-builder/Cargo.toml +++ b/crates/pyo-builder/Cargo.toml @@ -11,7 +11,7 @@ base64 = "0.23.1" flate2 = "1" futures = "0.3.34" hex = "0.4.3" -pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["command-signing"] } +pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["command-signing"] } reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls", "stream"] } serde = "1.0.229" serde_json = "1.0.154" diff --git a/crates/pyo-cli/Cargo.toml b/crates/pyo-cli/Cargo.toml index 5dca1999..3e68fab3 100644 --- a/crates/pyo-cli/Cargo.toml +++ b/crates/pyo-cli/Cargo.toml @@ -30,7 +30,7 @@ tar = { version = "0.4.46", default-features = false } tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "net", "io-util", "io-std", "time", "sync", "fs"] } tokio-tungstenite = { version = "0.29", features = ["rustls-tls-native-roots"] } toml = "0.9" -pyo-proto = { version = "0.5.0", path = "../pyo-proto" } +pyo-proto = { version = "0.5.1", path = "../pyo-proto" } [dev-dependencies] # The JSON Schema of pyo.jsonc, written from the config types by a test. diff --git a/crates/pyo-cli/src/pack.rs b/crates/pyo-cli/src/pack.rs index ad816f46..67a02cbc 100644 --- a/crates/pyo-cli/src/pack.rs +++ b/crates/pyo-cli/src/pack.rs @@ -41,12 +41,8 @@ pub fn is_env_file(name: &str) -> bool { ) } -/// The files of `root` to pack, in order. -pub fn list(root: &Path, with_env: bool) -> Result> { - // The defaults as an ignore file of the lowest precedence, so the - // folder's own files can keep what they leave out. - let defaults = std::env::temp_dir().join(format!("pyo-defaults-{}.ignore", std::process::id())); - std::fs::write(&defaults, DEFAULT_IGNORES)?; +/// A walk over `root` that heeds the folder's own ignore files. +fn walker(root: &Path) -> ignore::WalkBuilder { let mut walk = ignore::WalkBuilder::new(root); walk.hidden(false) .ignore(false) @@ -56,50 +52,76 @@ pub fn list(root: &Path, with_env: bool) -> Result> { .require_git(false) .parents(true) .follow_links(false) - .add_custom_ignore_filename(".pyoignore") - .sort_by_file_name(|a, b| a.cmp(b)) + .add_custom_ignore_filename(".pyoignore"); + walk +} + +/// The files of `root` to pack, in order. +pub fn list(root: &Path, with_env: bool) -> Result> { + // The defaults rank below the folder's own ignore files: they leave a + // path out only when those files say nothing about it, so a `!` line + // there keeps it. + let mut defaults = ignore::gitignore::GitignoreBuilder::new(root); + for line in DEFAULT_IGNORES.lines() { + defaults.add_line(None, line)?; + } + let defaults = defaults.build()?; + let own = std::sync::Mutex::new( + walker(root) + .build_matchers() + .pop() + .context("Couldn't read the folder's ignore files")?, + ); + let base = root.to_path_buf(); + let mut walk = walker(root); + walk.sort_by_file_name(|a, b| a.cmp(b)) .filter_entry(move |e| { let name = e.file_name().to_string_lossy(); if name == ".git" { return false; } - with_env || !(e.file_type().is_some_and(|t| !t.is_dir()) && is_env_file(&name)) - }); - if let Some(e) = walk.add_ignore(&defaults) { - let _ = std::fs::remove_file(&defaults); - return Err(e.into()); - } - let mut out = vec![]; - let result = (|| -> Result<()> { - for e in walk.build() { - let e = e?; - let Some(t) = e.file_type() else { continue }; - if t.is_dir() { - continue; + if !with_env && e.file_type().is_some_and(|t| !t.is_dir()) && is_env_file(&name) { + return false; } - let rel = e - .path() - .strip_prefix(root) - .unwrap_or(e.path()) - .to_path_buf(); - if rel.as_os_str().is_empty() { - continue; + let is_dir = e.file_type().is_some_and(|t| t.is_dir()); + if defaults.matched(e.path(), is_dir).is_ignore() { + // The walk got here, so the folder's files don't leave it out. + // Keep it only if they keep it on purpose. + let rel = e.path().strip_prefix(&base).unwrap_or(e.path()); + return own + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner) + .matched(rel, is_dir) + .is_whitelist(); } - let size = if t.is_file() { - e.metadata().map(|m| m.len()).unwrap_or(0) - } else { - 0 - }; - out.push(Entry { - rel, - abs: e.path().to_path_buf(), - size, - }); + true + }); + let mut out = vec![]; + for e in walk.build() { + let e = e?; + let Some(t) = e.file_type() else { continue }; + if t.is_dir() { + continue; + } + let rel = e + .path() + .strip_prefix(root) + .unwrap_or(e.path()) + .to_path_buf(); + if rel.as_os_str().is_empty() { + continue; } - Ok(()) - })(); - let _ = std::fs::remove_file(&defaults); - result?; + let size = if t.is_file() { + e.metadata().map(|m| m.len()).unwrap_or(0) + } else { + 0 + }; + out.push(Entry { + rel, + abs: e.path().to_path_buf(), + size, + }); + } Ok(out) } @@ -492,6 +514,58 @@ mod tests { assert!(names(&d.0, false).contains(&"node_modules/a/index.js".to_owned())); } + #[test] + fn defaults_rank_below_the_folders_ignore_files() { + // A `.gitignore` can keep node_modules too, and the default reaches + // nested ones. + let d = folder(&[ + (".gitignore", "!node_modules/\n"), + ("node_modules/a.js", "x"), + ("web/node_modules/b.js", "x"), + ]); + let got = names(&d.0, false); + assert!(got.contains(&"node_modules/a.js".to_owned()), "{got:?}"); + assert!(got.contains(&"web/node_modules/b.js".to_owned()), "{got:?}"); + let d = folder(&[ + ("web/node_modules/b.js", "x"), + ("web/index.js", "x"), + ("node_modules", "a file, not a folder"), + ]); + assert_eq!(names(&d.0, false), ["node_modules", "web/index.js"]); + // `.pyoignore` wins over `.gitignore`. + let d = folder(&[ + (".gitignore", "!node_modules/\n"), + (".pyoignore", "node_modules/\n"), + ("node_modules/a.js", "x"), + ]); + assert!(!names(&d.0, false).contains(&"node_modules/a.js".to_owned())); + } + + #[test] + fn lists_from_many_threads_at_once() { + let d = folder(&[ + (".pyoignore", "secret.txt\n"), + ("index.js", "x"), + ("secret.txt", "x"), + ("node_modules/a/index.js", "x"), + ]); + let root = d.0.clone(); + std::thread::scope(|s| { + let runs: Vec<_> = (0..8) + .map(|_| { + s.spawn(|| { + for _ in 0..50 { + assert_eq!(names(&root, false), [".pyoignore", "index.js"]); + } + }) + }) + .collect(); + for r in runs { + r.join().unwrap(); + } + }); + } + #[test] fn packs_the_same_files_the_same_way() { let d = folder(&[("a.txt", "hello"), ("b/c.txt", "world")]); diff --git a/crates/pyo-envd/Cargo.toml b/crates/pyo-envd/Cargo.toml index 09353f11..68235ad2 100644 --- a/crates/pyo-envd/Cargo.toml +++ b/crates/pyo-envd/Cargo.toml @@ -12,5 +12,5 @@ publish.workspace = true [dependencies] libc = "0.2.191" -pyo-proto = { version = "0.5.0", path = "../pyo-proto" } +pyo-proto = { version = "0.5.1", path = "../pyo-proto" } serde_json.workspace = true diff --git a/crates/pyo-flows/Cargo.toml b/crates/pyo-flows/Cargo.toml index b0c52c97..9cd2bc63 100644 --- a/crates/pyo-flows/Cargo.toml +++ b/crates/pyo-flows/Cargo.toml @@ -8,7 +8,7 @@ publish.workspace = true [dependencies] anyhow = "1.0.104" libc = "0.2.191" -pyo-proto = { version = "0.5.0", path = "../pyo-proto" } +pyo-proto = { version = "0.5.1", path = "../pyo-proto" } reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls"] } serde_json = "1.0.154" tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "time", "sync"] } diff --git a/crates/pyo-sandbox/Cargo.toml b/crates/pyo-sandbox/Cargo.toml index 49371151..cc8ce023 100644 --- a/crates/pyo-sandbox/Cargo.toml +++ b/crates/pyo-sandbox/Cargo.toml @@ -16,7 +16,7 @@ http-body-util = "0.1.5" hyper = { version = "1.12.0", features = ["client", "http1", "server"] } hyper-util = { version = "0.1.21", features = ["tokio"] } libc = "0.2.191" -pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["sandbox-token"] } +pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["sandbox-token"] } serde.workspace = true serde_json.workspace = true tokio.workspace = true diff --git a/crates/pyo-static/Cargo.toml b/crates/pyo-static/Cargo.toml index 3f8c4de4..c04635d3 100644 --- a/crates/pyo-static/Cargo.toml +++ b/crates/pyo-static/Cargo.toml @@ -12,7 +12,7 @@ axum = { version = "0.8.9", default-features = false, features = ["http1", "toki futures.workspace = true base64 = "0.23.1" hex = "0.4.3" -pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["command-signing"] } +pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["command-signing"] } reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls", "stream"] } serde.workspace = true serde_json.workspace = true diff --git a/deploy/release-notices.json b/deploy/release-notices.json index 17b4a706..232e2f14 100644 --- a/deploy/release-notices.json +++ b/deploy/release-notices.json @@ -1,5 +1,5 @@ { - "version": "0.5.0", + "version": "0.5.1", "minFrom": null, "manualOnly": false, "beforeYouUpdate": []