From b553a5f2c7274d086f0d5393fdff7a2ce60d692b Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 2 Apr 2024 10:15:31 +0800 Subject: [PATCH] fix(utils): resolve input path in `delete_dir_contents()` if it's a link --- src/utils/utils.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/utils.rs b/src/utils/utils.rs index e4d7e9adb95..b6ac5c38c0c 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -10,10 +10,13 @@ use retry::{retry, OperationResult}; use sha2::Sha256; use url::Url; -use crate::currentprocess::{cwdsource::CurrentDirSource, varsource::VarSource}; use crate::errors::*; use crate::utils::notifications::Notification; use crate::utils::raw; +use crate::{ + currentprocess::{cwdsource::CurrentDirSource, varsource::VarSource}, + utils::raw::open_dir_following_links, +}; use crate::{home_process, process}; #[cfg(not(windows))] @@ -611,7 +614,9 @@ where } pub(crate) fn delete_dir_contents(dir_path: &Path) { - match remove_dir_all::remove_dir_contents(dir_path) { + use remove_dir_all::RemoveDir; + + match open_dir_following_links(dir_path).and_then(|mut p| p.remove_dir_contents(None)) { Err(e) if e.kind() != io::ErrorKind::NotFound => { panic!("Unable to clean up {}: {:?}", dir_path.display(), e); }