Skip to content

Commit

Permalink
Add bad rep handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hkctkuy committed Dec 23, 2023
1 parent 450ef8f commit 36ad312
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
23 changes: 8 additions & 15 deletions casr/src/bin/casr-cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,9 @@ fn make_clusters(
// Get casreps with stacktraces and crashlines
let (casreps, badreports) = util::reports_from_paths(casreps, jobs);

// Handle bad reports
if !badreports.is_empty() {
fs::create_dir_all(format!("{}/clerr", &outpath.display()))?;
for report in badreports {
fs::copy(
&report,
format!(
"{}/clerr/{}",
&outpath.display(),
&report.file_name().unwrap().to_str().unwrap()
),
)?;
}
util::save_badreports(badreports, format!("{}/clerr", &outpath.display()))?;

Check warning on line 65 in casr/src/bin/casr-cluster.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cluster.rs#L65

Added line #L65 was not covered by tests
}

if casreps.len() < 2 {
Expand Down Expand Up @@ -417,10 +408,12 @@ fn update_clusters(
let (moved, removed) =
merge_clusters(&mut clusters, &mut deviant_clusters, oldpath, dedup)?;

Check warning on line 409 in casr/src/bin/casr-cluster.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cluster.rs#L408-L409

Added lines #L408 - L409 were not covered by tests
// Adjust stat
added += moved;
deduplicated += removed;
before = 0; // Impossible to know (proofed by @hkctkuy)
after -= moved + removed;
if moved != 0 || removed != 0 {
added += moved;
deduplicated += removed;
before = 0; // Impossible to know (proofed by @hkctkuy)
after -= moved + removed;
}

Check warning on line 416 in casr/src/bin/casr-cluster.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/bin/casr-cluster.rs#L411-L416

Added lines #L411 - L416 were not covered by tests
}
// Save deviant clusters
util::save_clusters(&deviant_clusters, oldpath)?;
Expand Down
22 changes: 21 additions & 1 deletion casr/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ pub fn cluster_from_dir(dir: &Path, jobs: usize) -> Result<Cluster> {
Ok(Cluster::new(i, Vec::new(), stacktraces, crashlines))
}

/// Save clusters to directory
/// Save clusters to given directory
///
/// # Arguments
///
Expand All @@ -536,3 +536,23 @@ pub fn save_clusters(clusters: &HashMap<usize, Cluster>, dir: &Path) -> Result<(
}
Ok(())
}

/// Save invalid CASR reports to given directory
///
/// # Arguments
///
/// * `badreports` - A vector of invalid CASR reports
///
/// * `dir` - out directory
pub fn save_badreports(badreports: Vec<PathBuf>, dir: String) -> Result<()> {
if !Path::new(&dir).exists() {
fs::create_dir_all(&dir)?;
}
for report in badreports {
fs::copy(
&report,
format!("{}/{}", dir, &report.file_name().unwrap().to_str().unwrap()),
)?;
}
Ok(())
}

Check warning on line 558 in casr/src/util.rs

View check run for this annotation

Codecov / codecov/patch

casr/src/util.rs#L547-L558

Added lines #L547 - L558 were not covered by tests

0 comments on commit 36ad312

Please sign in to comment.