From f4c83693f9e2445b441dfcf43838697d25d1a11f Mon Sep 17 00:00:00 2001 From: Peter Atashian Date: Sat, 3 Feb 2018 01:45:58 -0500 Subject: Go back to files directories and symlinks being mutually exclusive Be smarter about what a symlink is however --- src/libstd/sys/windows/fs.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index a49c3569b02..512c9cb838c 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -522,21 +522,27 @@ impl FileType { reparse_tag: reparse_tag, } } - pub fn is_dir(&self) -> bool { - self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0 + !self.is_symlink() && self.is_directory() } pub fn is_file(&self) -> bool { - self.attributes & c::FILE_ATTRIBUTE_DIRECTORY == 0 + !self.is_symlink() && !self.is_directory() } pub fn is_symlink(&self) -> bool { - self.is_reparse_point() && ( - self.reparse_tag == c::IO_REPARSE_TAG_SYMLINK || - self.reparse_tag == c::IO_REPARSE_TAG_MOUNT_POINT) + self.is_reparse_point() && self.is_reparse_tag_name_surrogate() + } + pub fn is_symlink_dir(&self) -> bool { + self.is_symlink() && self.is_directory() + } + fn is_directory(&self) -> bool { + self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0 } - pub fn is_reparse_point(&self) -> bool { + fn is_reparse_point(&self) -> bool { self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 } + fn is_reparse_tag_name_surrogate(&self) -> bool { + self.reparse_tag & 0x20000000 != 0 + } } impl DirBuilder { @@ -607,12 +613,10 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { for child in readdir(path)? { let child = child?; let child_type = child.file_type()?; - if child_type.is_dir() { - if child_type.is_reparse_point() { - rmdir(&child.path())?; - } else { - remove_dir_all_recursive(&child.path())?; - } + if child_type.is_symlink_dir() { + rmdir(&child.path())?; + } else if child_type.is_dir() { + remove_dir_all_recursive(&child.path())?; } else { unlink(&child.path())?; } -- cgit 1.4.1-3-g733a5