refactor: remove slicing from is_file_in_use

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.
This commit is contained in:
link2xt
2024-11-16 19:00:40 +00:00
committed by l
parent 399716a761
commit 514f0296c0

View File

@@ -942,15 +942,12 @@ pub async fn remove_unused_files(context: &Context) -> Result<()> {
Ok(()) Ok(())
} }
#[allow(clippy::indexing_slicing)]
fn is_file_in_use(files_in_use: &HashSet<String>, namespc_opt: Option<&str>, name: &str) -> bool { 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_to_check = if let Some(namespc) = namespc_opt {
let name_len = name.len(); let Some(name) = name.strip_suffix(namespc) else {
let namespc_len = namespc.len();
if name_len <= namespc_len || !name.ends_with(namespc) {
return false; return false;
} };
&name[..name_len - namespc_len] name
} else { } else {
name name
}; };