Skip to content

Commit ab1b36d

Browse files
authored
Merge pull request #981 from charlespierce/parse_json_only
Ignore non-json files when listing all package configs
2 parents e4ab360 + 75a3ed0 commit ab1b36d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/volta-core/src/inventory.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! of available tool versions.
33
44
use std::collections::BTreeSet;
5+
use std::ffi::OsStr;
56
use std::path::Path;
67

78
use crate::error::{Context, ErrorKind, Fallible};
@@ -60,11 +61,15 @@ pub fn package_configs() -> Fallible<BTreeSet<PackageConfig>> {
6061
// debug output, though
6162
.filter_map(|entry| match entry {
6263
Ok(dir_entry) => {
63-
// Ignore directory entries.
64-
if dir_entry.file_type().is_file() {
65-
Some(dir_entry.into_path())
66-
} else {
67-
None
64+
// Ignore directory entries and any files that don't have a .json extension.
65+
// This will prevent us from trying to parse OS-generated files as package
66+
// configs (e.g. `.DS_Store` on macOS)
67+
let extension = dir_entry.path().extension().and_then(OsStr::to_str);
68+
match (dir_entry.file_type().is_file(), extension) {
69+
(true, Some(ext)) if ext.eq_ignore_ascii_case("json") => {
70+
Some(dir_entry.into_path())
71+
}
72+
_ => None,
6873
}
6974
}
7075
Err(e) => {

0 commit comments

Comments
 (0)