Skip to content

Commit

Permalink
fix(parse): case insensitive file name match (#269)
Browse files Browse the repository at this point in the history
* fix(parse): case insensitive file name match
  • Loading branch information
joe-prosser authored Apr 8, 2024
1 parent 7a67a44 commit a8e1071
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased
- Fixes issue when getting streams that have multiple filters on single user property
- Fixes issue where upper case file names would not be matched in `parse`

# v0.24.0
- BREAKING: the `--context` option is now required. Users need to opt
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/parse/emls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn parse(client: &Client, args: &ParseEmlArgs, pool: &mut Pool) -> Result<()
ensure_uip_user_consents_to_ai_unit_charge(client.base_url())?;
}

let eml_paths = get_files_in_directory(directory, "eml")?;
let eml_paths = get_files_in_directory(directory, "eml", true)?;
let statistics = Arc::new(Statistics::new());
let _progress = get_progress_bar(eml_paths.len() as u64, &statistics);

Expand Down
14 changes: 12 additions & 2 deletions cli/src/commands/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,21 @@ impl Statistics {
}
}

pub fn get_files_in_directory(directory: &PathBuf, extension: &str) -> Result<Vec<DirEntry>> {
pub fn get_files_in_directory(
directory: &PathBuf,
target_extension: &str,
case_insensitive: bool,
) -> Result<Vec<DirEntry>> {
Ok(std::fs::read_dir(directory)?
.filter_map(|path| {
let path = path.ok()?;
if path.path().extension().is_some_and(|msg| msg == extension) {
if path.path().extension().is_some_and(|extension| {
if case_insensitive {
*extension.to_ascii_lowercase() == *target_extension.to_ascii_lowercase()
} else {
extension == target_extension
}
}) {
Some(path)
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/parse/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn parse(client: &Client, args: &ParseMsgArgs) -> Result<()> {
ensure_uip_user_consents_to_ai_unit_charge(client.base_url())?;
}

let msg_paths = get_files_in_directory(directory, "msg")?;
let msg_paths = get_files_in_directory(directory, "msg", true)?;
let statistics = Arc::new(Statistics::new());
let _progress = get_progress_bar(msg_paths.len() as u64, &statistics);
let source = client.get_source(source.clone())?;
Expand Down

0 comments on commit a8e1071

Please sign in to comment.