Skip to content

Commit

Permalink
Merge pull request volta-cli#981 from charlespierce/parse_json_only
Browse files Browse the repository at this point in the history
Ignore non-json files when listing all package configs
  • Loading branch information
chriskrycho committed Apr 30, 2021
2 parents e4ab360 + 75a3ed0 commit ab1b36d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/volta-core/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! of available tool versions.

use std::collections::BTreeSet;
use std::ffi::OsStr;
use std::path::Path;

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

0 comments on commit ab1b36d

Please sign in to comment.