From 15d652088edba36793b400b1e9b1dc455ed03f72 Mon Sep 17 00:00:00 2001 From: BlackDex Date: Wed, 6 Dec 2023 22:22:19 +0100 Subject: [PATCH] Do not delete dir on file delete Previously during a `delete_file` check we also tried to delete the parent directory and ignored all errors, like not being empty for example. Since this function is called `delete_file` and does not mention anything in regards to a directory i have removed that code and it will now only delete the file and leave the rest as-is. If this somehow is still needed or wanted, which i do not think we want, then we should create a new function. Fixes #4081 --- src/util.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/util.rs b/src/util.rs index 2afd3ed8..9b43116f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -363,15 +363,7 @@ pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> } pub fn delete_file(path: &str) -> IOResult<()> { - let res = fs::remove_file(path); - - if let Some(parent) = Path::new(path).parent() { - // If the directory isn't empty, this returns an error, which we ignore - // We only want to delete the folder if it's empty - fs::remove_dir(parent).ok(); - } - - res + fs::remove_file(path) } pub fn get_display_size(size: i32) -> String {