mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 02:37:21 +00:00
windows: Implement fs::trash_file
and fs::trash_dir
(#17711)
https://github.com/user-attachments/assets/43370cee-26a5-4d27-b86f-656127e03b4a Release Notes: - N/A
This commit is contained in:
parent
ee96d69e37
commit
af819bf661
2 changed files with 38 additions and 0 deletions
|
@ -483,6 +483,7 @@ version = "0.58"
|
||||||
features = [
|
features = [
|
||||||
"implement",
|
"implement",
|
||||||
"Foundation_Numerics",
|
"Foundation_Numerics",
|
||||||
|
"Storage",
|
||||||
"System",
|
"System",
|
||||||
"System_Threading",
|
"System_Threading",
|
||||||
"UI_ViewManagement",
|
"UI_ViewManagement",
|
||||||
|
|
|
@ -342,6 +342,24 @@ impl Fs for RealFs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
async fn trash_file(&self, path: &Path, _options: RemoveOptions) -> Result<()> {
|
||||||
|
use windows::{
|
||||||
|
core::HSTRING,
|
||||||
|
Storage::{StorageDeleteOption, StorageFile},
|
||||||
|
};
|
||||||
|
// todo(windows)
|
||||||
|
// When new version of `windows-rs` release, make this operation `async`
|
||||||
|
let path = path.canonicalize()?.to_string_lossy().to_string();
|
||||||
|
let path_str = path.trim_start_matches("\\\\?\\");
|
||||||
|
if path_str.is_empty() {
|
||||||
|
anyhow::bail!("File path is empty!");
|
||||||
|
}
|
||||||
|
let file = StorageFile::GetFileFromPathAsync(&HSTRING::from(path_str))?.get()?;
|
||||||
|
file.DeleteAsync(StorageDeleteOption::Default)?.get()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
async fn trash_dir(&self, path: &Path, options: RemoveOptions) -> Result<()> {
|
async fn trash_dir(&self, path: &Path, options: RemoveOptions) -> Result<()> {
|
||||||
self.trash_file(path, options).await
|
self.trash_file(path, options).await
|
||||||
|
@ -352,6 +370,25 @@ impl Fs for RealFs {
|
||||||
self.trash_file(path, options).await
|
self.trash_file(path, options).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
async fn trash_dir(&self, path: &Path, _options: RemoveOptions) -> Result<()> {
|
||||||
|
use windows::{
|
||||||
|
core::HSTRING,
|
||||||
|
Storage::{StorageDeleteOption, StorageFolder},
|
||||||
|
};
|
||||||
|
|
||||||
|
let path = path.canonicalize()?.to_string_lossy().to_string();
|
||||||
|
let path_str = path.trim_start_matches("\\\\?\\");
|
||||||
|
if path_str.is_empty() {
|
||||||
|
anyhow::bail!("Folder path is empty!");
|
||||||
|
}
|
||||||
|
// todo(windows)
|
||||||
|
// When new version of `windows-rs` release, make this operation `async`
|
||||||
|
let folder = StorageFolder::GetFolderFromPathAsync(&HSTRING::from(path_str))?.get()?;
|
||||||
|
folder.DeleteAsync(StorageDeleteOption::Default)?.get()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>> {
|
async fn open_sync(&self, path: &Path) -> Result<Box<dyn io::Read>> {
|
||||||
Ok(Box::new(std::fs::File::open(path)?))
|
Ok(Box::new(std::fs::File::open(path)?))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue