Skip to content

Commit 5bf2140

Browse files
authored
Merge pull request #102 from golemcloud/fix-golem-exec-python
Hand-written remove-dir-all to solve infinite loop
2 parents 3a6c966 + bac38f4 commit 5bf2140

File tree

3 files changed

+70
-62
lines changed

3 files changed

+70
-62
lines changed

Cargo.lock

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

exec/exec/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ hex = "0.4.3"
2727
indoc = "2.0.6"
2828
log = { workspace = true }
2929
rquickjs = { version = "0.9.0", default-features = false, features = ["futures", "bindgen", "loader", "macro"], optional = true }
30-
rustpython = { git = "https://github.com/RustPython/RustPython", rev = "d8f1d188c394eb2d970d3ebe95f0d3d7658f31a3", default-features = false, features = ["stdlib", "stdio", "importlib", "freeze-stdlib"], optional = true }
30+
rustpython = { git = "https://github.com/RustPython/RustPython", rev = "6ead82154e06a4490c0a87b966db5528eee13070", default-features = false, features = ["stdlib", "stdio", "importlib", "freeze-stdlib"], optional = true }
3131
wasi = { workspace = true }
3232
wasi-logger = "0.1.2"
3333
wit-bindgen = { version = "0.40.0" }

exec/exec/src/python/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustpython::{vm, InterpreterConfig};
1111
use std::cell::RefCell;
1212
use std::path::{Path, PathBuf};
1313
use std::sync::atomic::AtomicU32;
14+
use std::{fs, io};
1415
use wstd::time::Instant;
1516

1617
static TEMP_DIR_COUNTER: AtomicU32 = AtomicU32::new(0);
@@ -395,7 +396,21 @@ impl Drop for PythonSession {
395396
state.interpreter.finalize(state.last_error.take());
396397
}
397398

398-
let _ = std::fs::remove_dir_all(&self.data_root);
399-
let _ = std::fs::remove_dir_all(&self.module_root);
399+
let _ = remove_dir_all(&self.data_root);
400+
let _ = remove_dir_all(&self.module_root);
400401
}
401402
}
403+
404+
pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
405+
for child in fs::read_dir(&path)? {
406+
let child = child?;
407+
let metadata = child.metadata()?;
408+
let path = child.path();
409+
if metadata.is_dir() {
410+
remove_dir_all(&path)?;
411+
} else if metadata.is_file() {
412+
fs::remove_file(&path)?;
413+
}
414+
}
415+
fs::remove_dir(&path)
416+
}

0 commit comments

Comments
 (0)