Skip to content

Commit d6d13fb

Browse files
Address PR comments: is_dir/is_file glob errors and toml syntax
- `is_dir` and `is_file` now return an error explicitly stating "Globbing not supported for multiple paths" if a glob pattern resolves to > 1 file. This mirrors bash behavior. - Updated `eldritch-libreport/Cargo.toml` to use `glob = { workspace = true }` syntax. Co-authored-by: hulto <7121375+hulto@users.noreply.github.com>
1 parent 8c8467a commit d6d13fb

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

implants/lib/eldritch/stdlib/eldritch-libfile/src/std/is_dir_impl.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ use glob::glob;
66
pub fn is_dir(path: String) -> Result<bool, String> {
77
if path.contains('*') || path.contains('?') || path.contains('[') {
88
let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?;
9-
if let Some(Ok(first_match)) = paths.next() {
10-
Ok(first_match.is_dir())
9+
let first_match = paths.next();
10+
let second_match = paths.next();
11+
12+
if second_match.is_some() {
13+
return Err(format!(
14+
"Globbing not supported for multiple paths (pattern: {path})"
15+
));
16+
}
17+
18+
if let Some(Ok(match_path)) = first_match {
19+
Ok(match_path.is_dir())
1120
} else {
1221
Ok(false)
1322
}

implants/lib/eldritch/stdlib/eldritch-libfile/src/std/is_file_impl.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ use glob::glob;
66
pub fn is_file(path: String) -> Result<bool, String> {
77
if path.contains('*') || path.contains('?') || path.contains('[') {
88
let mut paths = glob(&path).map_err(|e| format!("Invalid glob pattern {path}: {e}"))?;
9-
if let Some(Ok(first_match)) = paths.next() {
10-
Ok(first_match.is_file())
9+
let first_match = paths.next();
10+
let second_match = paths.next();
11+
12+
if second_match.is_some() {
13+
return Err(format!(
14+
"Globbing not supported for multiple paths (pattern: {path})"
15+
));
16+
}
17+
18+
if let Some(Ok(match_path)) = first_match {
19+
Ok(match_path.is_file())
1120
} else {
1221
Ok(false)
1322
}

implants/lib/eldritch/stdlib/eldritch-libreport/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ eldritch-agent = { workspace = true, optional = true }
1010
pb = { workspace = true, optional = true }
1111
nix = { workspace = true, optional = true }
1212
spin = { version = "0.10.0", features = ["rwlock"] }
13-
glob.workspace = true
13+
glob = { workspace = true }
1414
[target.'cfg(not(target_os = "linux"))'.dependencies]
1515
xcap = { workspace = true, optional = true }
1616
image = { version = "0.25", optional = true }

0 commit comments

Comments
 (0)