mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
do not call fs::remove_dir_all() implicitly on non-files; deleting folders is not needed and calling remove_dir_all() is considered harmful
This commit is contained in:
@@ -843,13 +843,16 @@ pub fn dc_get_filebytes(context: &Context, path: impl AsRef<std::path::Path>) ->
|
|||||||
|
|
||||||
pub fn dc_delete_file(context: &Context, path: impl AsRef<std::path::Path>) -> bool {
|
pub fn dc_delete_file(context: &Context, path: impl AsRef<std::path::Path>) -> bool {
|
||||||
let path_abs = dc_get_abs_path_safe(context, &path);
|
let path_abs = dc_get_abs_path_safe(context, &path);
|
||||||
let res = if path_abs.is_file() {
|
if !path_abs.is_file() {
|
||||||
fs::remove_file(path_abs)
|
warn!(
|
||||||
} else {
|
context,
|
||||||
fs::remove_dir_all(path_abs)
|
"Will not delete directory \"{}\".",
|
||||||
};
|
path.as_ref().display()
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
match res {
|
match fs::remove_file(path_abs) {
|
||||||
Ok(_) => true,
|
Ok(_) => true,
|
||||||
Err(_err) => {
|
Err(_err) => {
|
||||||
warn!(context, "Cannot delete \"{}\".", path.as_ref().display());
|
warn!(context, "Cannot delete \"{}\".", path.as_ref().display());
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
assert!(dc_delete_file(context, "$BLOBDIR/dada"));
|
assert!(dc_delete_file(context, "$BLOBDIR/dada"));
|
||||||
assert!(dc_create_folder(context, "$BLOBDIR/foobar-folder"));
|
assert!(dc_create_folder(context, "$BLOBDIR/foobar-folder"));
|
||||||
assert!(dc_file_exist(context, "$BLOBDIR/foobar-folder",));
|
assert!(dc_file_exist(context, "$BLOBDIR/foobar-folder",));
|
||||||
assert!(dc_delete_file(context, "$BLOBDIR/foobar-folder"));
|
assert!(!dc_delete_file(context, "$BLOBDIR/foobar-folder"));
|
||||||
let fn0: *mut libc::c_char = dc_get_fine_pathNfilename(
|
let fn0: *mut libc::c_char = dc_get_fine_pathNfilename(
|
||||||
context,
|
context,
|
||||||
b"$BLOBDIR\x00" as *const u8 as *const libc::c_char,
|
b"$BLOBDIR\x00" as *const u8 as *const libc::c_char,
|
||||||
|
|||||||
Reference in New Issue
Block a user