Go back to files directories and symlinks being mutually exclusive

Be smarter about what a symlink is however
This commit is contained in:
Peter Atashian
2018-02-03 01:45:58 -05:00
parent 259b0329d4
commit f4c83693f9

View File

@@ -522,21 +522,27 @@ impl FileType {
reparse_tag: reparse_tag, reparse_tag: reparse_tag,
} }
} }
pub fn is_dir(&self) -> bool { 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 { 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 { pub fn is_symlink(&self) -> bool {
self.is_reparse_point() && ( self.is_reparse_point() && self.is_reparse_tag_name_surrogate()
self.reparse_tag == c::IO_REPARSE_TAG_SYMLINK ||
self.reparse_tag == c::IO_REPARSE_TAG_MOUNT_POINT)
} }
pub fn is_reparse_point(&self) -> bool { 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
}
fn is_reparse_point(&self) -> bool {
self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
} }
fn is_reparse_tag_name_surrogate(&self) -> bool {
self.reparse_tag & 0x20000000 != 0
}
} }
impl DirBuilder { impl DirBuilder {
@@ -607,12 +613,10 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
for child in readdir(path)? { for child in readdir(path)? {
let child = child?; let child = child?;
let child_type = child.file_type()?; let child_type = child.file_type()?;
if child_type.is_dir() { if child_type.is_symlink_dir() {
if child_type.is_reparse_point() {
rmdir(&child.path())?; rmdir(&child.path())?;
} else { } else if child_type.is_dir() {
remove_dir_all_recursive(&child.path())?; remove_dir_all_recursive(&child.path())?;
}
} else { } else {
unlink(&child.path())?; unlink(&child.path())?;
} }