Skip to content

Commit caaf860

Browse files
committed
Use to_str instead of lossy
1 parent a316313 commit caaf860

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

fact/src/bpf/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,16 @@ impl Bpf {
133133
let mut new_paths = Vec::with_capacity(paths_config.len());
134134
let mut builder = GlobSetBuilder::new();
135135
for p in paths_config.iter() {
136+
let Some(glob_str) = p.to_str() else {
137+
bail!("failed to convert path {} to string", p.display());
138+
};
139+
136140
builder.add(
137-
Glob::new(&p.to_string_lossy())
138-
.with_context(|| format!("invalid glob {}", p.display()))
141+
Glob::new(glob_str)
142+
.with_context(|| format!("invalid glob {}", glob_str))
139143
.unwrap(),
140144
);
145+
141146
let prefix = path_prefix_t::try_from(p)?;
142147
path_prefix.insert(&prefix.into(), 0, 0)?;
143148
new_paths.push(prefix);

fact/src/host_scanner.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::{
2525
sync::Arc,
2626
};
2727

28-
use anyhow::Context;
28+
use anyhow::{Context, bail};
2929
use aya::maps::MapData;
3030
use fact_ebpf::{inode_key_t, inode_value_t};
3131
use log::{debug, info, warn};
@@ -85,7 +85,11 @@ impl HostScanner {
8585
}
8686

8787
fn scan_inner(&self, path: &Path) -> anyhow::Result<()> {
88-
for entry in glob::glob(&path.to_string_lossy())? {
88+
let Some(glob_str) = path.to_str() else {
89+
bail!("invalid path {}", path.display());
90+
};
91+
92+
for entry in glob::glob(glob_str)? {
8993
match entry {
9094
Ok(path) => {
9195
if path.is_file() {

0 commit comments

Comments
 (0)