diff options
author | Ali Hasani <a.hassssani@gmail.com> | 2020-05-18 17:20:44 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-18 14:50:44 +0200 |
commit | c3ec16535f55030ded8d76a82f0e1feaa1c8a3de (patch) | |
tree | 829767967b37f23f32718988dbecb73f88bd87c8 /cli/ops/fs.rs | |
parent | 2a038eafcd1bd715f865e3b4642575af05893dc5 (diff) |
Make Deno.remove() work with directory symlinks on windows (#5488)
Diffstat (limited to 'cli/ops/fs.rs')
-rw-r--r-- | cli/ops/fs.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 116366c8d..068dbaf7e 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -394,13 +394,29 @@ fn op_remove( let is_sync = args.promise_id.is_none(); blocking_json(is_sync, move || { + #[cfg(not(unix))] + use std::os::windows::prelude::MetadataExt; + let metadata = std::fs::symlink_metadata(&path)?; + debug!("op_remove {} {}", path.display(), recursive); let file_type = metadata.file_type(); - if file_type.is_file() || file_type.is_symlink() { + if file_type.is_file() { std::fs::remove_file(&path)?; } else if recursive { std::fs::remove_dir_all(&path)?; + } else if file_type.is_symlink() { + #[cfg(unix)] + std::fs::remove_file(&path)?; + #[cfg(not(unix))] + { + use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY; + if metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY != 0 { + std::fs::remove_dir(&path)?; + } else { + std::fs::remove_file(&path)?; + } + } } else { std::fs::remove_dir(&path)?; } |