diff --git a/pdl-live-react/src-tauri/Cargo.lock b/pdl-live-react/src-tauri/Cargo.lock index f3f6acca7..82bc1528e 100644 --- a/pdl-live-react/src-tauri/Cargo.lock +++ b/pdl-live-react/src-tauri/Cargo.lock @@ -1376,6 +1376,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs4" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4" +dependencies = [ + "rustix 1.0.5", + "windows-sys 0.59.0", +] + [[package]] name = "futf" version = "0.1.5" @@ -3367,6 +3377,7 @@ dependencies = [ "base64ct", "dirs", "duct", + "fs4", "futures", "indexmap 2.9.0", "minijinja", diff --git a/pdl-live-react/src-tauri/Cargo.toml b/pdl-live-react/src-tauri/Cargo.toml index a26aa414a..0bf71e50c 100644 --- a/pdl-live-react/src-tauri/Cargo.toml +++ b/pdl-live-react/src-tauri/Cargo.toml @@ -45,6 +45,7 @@ tokio = { version = "1.44.1", features = ["io-std"] } indexmap = { version = "2.9.0", features = ["serde"] } rustpython-stdlib = { version = "0.4.0", features = ["zlib"] } schemars = "0.8.22" +fs4 = "0.13.1" [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-cli = "2" diff --git a/pdl-live-react/src-tauri/src/pdl/extract.rs b/pdl-live-react/src-tauri/src/pdl/extract.rs index a33416288..2489b7b07 100644 --- a/pdl-live-react/src-tauri/src/pdl/extract.rs +++ b/pdl-live-react/src-tauri/src/pdl/extract.rs @@ -31,24 +31,43 @@ fn extract_values_iter(program: &PdlBlock, field: &str, values: &mut Vec .array .iter() .for_each(|p| extract_values_iter(p, field, values)), - PdlBlock::Text(b) => b - .text - .iter() - .for_each(|p| extract_values_iter(p, field, values)), - PdlBlock::LastOf(b) => b - .last_of - .iter() - .for_each(|p| extract_values_iter(p, field, values)), + PdlBlock::Text(b) => { + b.text + .iter() + .for_each(|p| extract_values_iter(p, field, values)); + if let Some(defs) = &b.defs { + defs.values() + .for_each(|p| extract_values_iter(p, field, values)); + } + } + PdlBlock::LastOf(b) => { + b.last_of + .iter() + .for_each(|p| extract_values_iter(p, field, values)); + if let Some(defs) = &b.defs { + defs.values() + .for_each(|p| extract_values_iter(p, field, values)); + } + } PdlBlock::If(b) => { extract_values_iter(&b.then, field, values); if let Some(else_) = &b.else_ { extract_values_iter(else_, field, values); } + if let Some(defs) = &b.defs { + defs.values() + .for_each(|p| extract_values_iter(p, field, values)); + } } PdlBlock::Object(b) => b .object .values() .for_each(|p| extract_values_iter(p, field, values)), + + PdlBlock::Function(b) => { + extract_values_iter(&b.return_, field, values); + } + _ => {} } } diff --git a/pdl-live-react/src-tauri/src/pdl/pull.rs b/pdl-live-react/src-tauri/src/pdl/pull.rs index cdb42a04a..cb7763c61 100644 --- a/pdl-live-react/src-tauri/src/pdl/pull.rs +++ b/pdl-live-react/src-tauri/src/pdl/pull.rs @@ -1,6 +1,7 @@ use ::std::io::Error; use duct::cmd; +use fs4::fs_std::FileExt; use rayon::prelude::*; use crate::pdl::ast::PdlBlock; @@ -46,8 +47,20 @@ fn ollama_exists(model: &str) -> bool { /// The Ollama implementation of a single model pull fn ollama_pull_if_needed(model: &str) -> Result<(), Error> { - if !ollama_exists(model) { - cmd!("ollama", "pull", model).stdout_to_stderr().run()?; - } - Ok(()) + let path = ::std::env::temp_dir().join(format!("pdl-ollama-pull-{model}")); + let f = ::std::fs::File::create(path)?; + f.lock_exclusive()?; + + // don't ? the cmd! so that we can "finally" unlock the file + let res = if !ollama_exists(model) { + cmd!("ollama", "pull", model) + .stdout_to_stderr() + .run() + .and_then(|_| Ok(())) + } else { + Ok(()) + }; + + FileExt::unlock(&f)?; + res }