mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +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(())
|
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
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user