mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
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:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user