Skip to content

Commit f6306b2

Browse files
committed
Cleanup old test dirs before running the integration test.
1 parent b0124b5 commit f6306b2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/bin/integration_tests.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4848
}
4949
println!();
5050

51+
// Clean up any leftover temporary directories from previous runs
52+
println!("--- Cleaning up leftover temporary directories ---");
53+
cleanup_leftover_temp_directories(&project_root)?;
54+
println!();
55+
5156
let mut failed_projects: Vec<(String, String)> = Vec::new();
5257

5358
// Process each test directory
@@ -101,6 +106,46 @@ fn find_test_directories(
101106
Ok(dirs)
102107
}
103108

109+
fn cleanup_leftover_temp_directories(
110+
project_root: &Path,
111+
) -> Result<(), Box<dyn std::error::Error>> {
112+
let mut cleaned_count = 0;
113+
114+
for entry in fs::read_dir(project_root)? {
115+
let entry = entry?;
116+
let path = entry.path();
117+
118+
if path.is_dir()
119+
&& let Some(dir_name) = path.file_name().and_then(|n| n.to_str())
120+
{
121+
// Match directories starting with "servicemaker-" and containing at least one more "-"
122+
// This matches patterns like "servicemaker-<name>-<pid>"
123+
if dir_name.starts_with("servicemaker-") && dir_name.matches('-').count() >= 2 {
124+
println!("Removing leftover temporary directory: {}", path.display());
125+
fs::remove_dir_all(&path).map_err(|e| {
126+
format!(
127+
"Failed to remove leftover temporary directory {}: {}",
128+
path.display(),
129+
e
130+
)
131+
})?;
132+
cleaned_count += 1;
133+
}
134+
}
135+
}
136+
137+
if cleaned_count > 0 {
138+
println!(
139+
"✓ Removed {} leftover temporary directory/ies",
140+
cleaned_count
141+
);
142+
} else {
143+
println!(" (No leftover temporary directories found)");
144+
}
145+
146+
Ok(())
147+
}
148+
104149
fn test_project(
105150
project_root: &Path,
106151
test_dir: &Path,

0 commit comments

Comments
 (0)