Skip to content

Commit

Permalink
Do not delete dir on file delete
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BlackDex committed Dec 6, 2023
1 parent fd9a059 commit 15d6520
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 15d6520

Please sign in to comment.