Skip to content

Commit

Permalink
refactor: remove slicing from is_file_in_use
Browse files Browse the repository at this point in the history
There is a change in behavior for the case
when name is the same as the suffix
(`name_len` == `namespc_len`),
but normally `files_in_use` should not contain empty filenames.
  • Loading branch information
link2xt committed Nov 18, 2024
1 parent 399716a commit 7a62839
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,12 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
Ok(())
}

#[allow(clippy::indexing_slicing)]
fn is_file_in_use(files_in_use: &HashSet<String>, namespc_opt: Option<&str>, name: &str) -> bool {
let name_to_check = if let Some(namespc) = namespc_opt {
let name_len = name.len();
let namespc_len = namespc.len();
if name_len <= namespc_len || !name.ends_with(namespc) {
let Some(name) = name.strip_suffix(namespc) else {
return false;
}
&name[..name_len - namespc_len]
};
name
} else {
name
};
Expand Down

0 comments on commit 7a62839

Please sign in to comment.