Skip to content

Commit 5de9648

Browse files
committed
fix: rust pull logic may not always pull
1) extract was not traversing completely, thus missing some model references 2) ollama pull itself (the CLI) may double/triple fetch if concurrent ollama pulls are launched. this PR introduces a file lock to avoid this. in github actions, we were running out of disk space due to this issue. Signed-off-by: Nick Mitchell <[email protected]>
1 parent 206cf63 commit 5de9648

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

pdl-live-react/src-tauri/Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdl-live-react/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tokio = { version = "1.44.1", features = ["io-std"] }
4545
indexmap = { version = "2.9.0", features = ["serde"] }
4646
rustpython-stdlib = { version = "0.4.0", features = ["zlib"] }
4747
schemars = "0.8.22"
48+
fs4 = "0.13.1"
4849

4950
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
5051
tauri-plugin-cli = "2"

pdl-live-react/src-tauri/src/pdl/extract.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,43 @@ fn extract_values_iter(program: &PdlBlock, field: &str, values: &mut Vec<String>
3131
.array
3232
.iter()
3333
.for_each(|p| extract_values_iter(p, field, values)),
34-
PdlBlock::Text(b) => b
35-
.text
36-
.iter()
37-
.for_each(|p| extract_values_iter(p, field, values)),
38-
PdlBlock::LastOf(b) => b
39-
.last_of
40-
.iter()
41-
.for_each(|p| extract_values_iter(p, field, values)),
34+
PdlBlock::Text(b) => {
35+
b.text
36+
.iter()
37+
.for_each(|p| extract_values_iter(p, field, values));
38+
if let Some(defs) = &b.defs {
39+
defs.values()
40+
.for_each(|p| extract_values_iter(p, field, values));
41+
}
42+
}
43+
PdlBlock::LastOf(b) => {
44+
b.last_of
45+
.iter()
46+
.for_each(|p| extract_values_iter(p, field, values));
47+
if let Some(defs) = &b.defs {
48+
defs.values()
49+
.for_each(|p| extract_values_iter(p, field, values));
50+
}
51+
}
4252
PdlBlock::If(b) => {
4353
extract_values_iter(&b.then, field, values);
4454
if let Some(else_) = &b.else_ {
4555
extract_values_iter(else_, field, values);
4656
}
57+
if let Some(defs) = &b.defs {
58+
defs.values()
59+
.for_each(|p| extract_values_iter(p, field, values));
60+
}
4761
}
4862
PdlBlock::Object(b) => b
4963
.object
5064
.values()
5165
.for_each(|p| extract_values_iter(p, field, values)),
66+
67+
PdlBlock::Function(b) => {
68+
extract_values_iter(&b.return_, field, values);
69+
}
70+
5271
_ => {}
5372
}
5473
}

pdl-live-react/src-tauri/src/pdl/pull.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use ::std::io::Error;
22

33
use duct::cmd;
4+
use fs4::fs_std::FileExt;
45
use rayon::prelude::*;
56

67
use crate::pdl::ast::PdlBlock;
@@ -46,8 +47,20 @@ fn ollama_exists(model: &str) -> bool {
4647

4748
/// The Ollama implementation of a single model pull
4849
fn ollama_pull_if_needed(model: &str) -> Result<(), Error> {
49-
if !ollama_exists(model) {
50-
cmd!("ollama", "pull", model).stdout_to_stderr().run()?;
51-
}
52-
Ok(())
50+
let path = ::std::env::temp_dir().join(format!("pdl-ollama-pull-{model}"));
51+
let f = ::std::fs::File::create(path)?;
52+
f.lock_exclusive()?;
53+
54+
// don't ? the cmd! so that we can "finally" unlock the file
55+
let res = if !ollama_exists(model) {
56+
cmd!("ollama", "pull", model)
57+
.stdout_to_stderr()
58+
.run()
59+
.and_then(|_| Ok(()))
60+
} else {
61+
Ok(())
62+
};
63+
64+
FileExt::unlock(&f)?;
65+
res
5366
}

0 commit comments

Comments
 (0)