Skip to content

Commit f4c8369

Browse files
committed
Go back to files directories and symlinks being mutually exclusive
Be smarter about what a symlink is however
1 parent 259b032 commit f4c8369

File tree

1 file changed

+17
-13
lines changed
  • src/libstd/sys/windows

1 file changed

+17
-13
lines changed

src/libstd/sys/windows/fs.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,27 @@ impl FileType {
522522
reparse_tag: reparse_tag,
523523
}
524524
}
525-
526525
pub fn is_dir(&self) -> bool {
527-
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
526+
!self.is_symlink() && self.is_directory()
528527
}
529528
pub fn is_file(&self) -> bool {
530-
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY == 0
529+
!self.is_symlink() && !self.is_directory()
531530
}
532531
pub fn is_symlink(&self) -> bool {
533-
self.is_reparse_point() && (
534-
self.reparse_tag == c::IO_REPARSE_TAG_SYMLINK ||
535-
self.reparse_tag == c::IO_REPARSE_TAG_MOUNT_POINT)
532+
self.is_reparse_point() && self.is_reparse_tag_name_surrogate()
533+
}
534+
pub fn is_symlink_dir(&self) -> bool {
535+
self.is_symlink() && self.is_directory()
536+
}
537+
fn is_directory(&self) -> bool {
538+
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
536539
}
537-
pub fn is_reparse_point(&self) -> bool {
540+
fn is_reparse_point(&self) -> bool {
538541
self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
539542
}
543+
fn is_reparse_tag_name_surrogate(&self) -> bool {
544+
self.reparse_tag & 0x20000000 != 0
545+
}
540546
}
541547

542548
impl DirBuilder {
@@ -607,12 +613,10 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
607613
for child in readdir(path)? {
608614
let child = child?;
609615
let child_type = child.file_type()?;
610-
if child_type.is_dir() {
611-
if child_type.is_reparse_point() {
612-
rmdir(&child.path())?;
613-
} else {
614-
remove_dir_all_recursive(&child.path())?;
615-
}
616+
if child_type.is_symlink_dir() {
617+
rmdir(&child.path())?;
618+
} else if child_type.is_dir() {
619+
remove_dir_all_recursive(&child.path())?;
616620
} else {
617621
unlink(&child.path())?;
618622
}

0 commit comments

Comments
 (0)