about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-08 07:38:11 +0000
committerbors <bors@rust-lang.org>2016-02-08 07:38:11 +0000
commite06f6928cb840a018706cabf75ab2bf3807551b1 (patch)
tree2ee110510e30d79e2f426e3786fb9e27f9c06e26 /src/libstd/sys
parent7fce5037a9040a3443f796c577b88d50ca5846a0 (diff)
parentd1bfe9bccf8a1632ffb8d29ee97be137a0e71045 (diff)
downloadrust-e06f6928cb840a018706cabf75ab2bf3807551b1.tar.gz
rust-e06f6928cb840a018706cabf75ab2bf3807551b1.zip
Auto merge of #31468 - pitdicker:fs_tests_cleanup, r=alexcrichton
See #29412
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/fs.rs11
-rw-r--r--src/libstd/sys/windows/fs.rs13
2 files changed, 22 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index 727624dad7c..ee81c516e33 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -627,10 +627,19 @@ pub fn rmdir(p: &Path) -> io::Result<()> {
 }
 
 pub fn remove_dir_all(path: &Path) -> io::Result<()> {
+    let filetype = try!(lstat(path)).file_type();
+    if filetype.is_symlink() {
+        unlink(path)
+    } else {
+        remove_dir_all_recursive(path)
+    }
+}
+
+fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
     for child in try!(readdir(path)) {
         let child = try!(child);
         if try!(child.file_type()).is_dir() {
-            try!(remove_dir_all(&child.path()));
+            try!(remove_dir_all_recursive(&child.path()));
         } else {
             try!(unlink(&child.path()));
         }
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index 16d337fcc70..3062d38f8c2 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -552,11 +552,22 @@ pub fn rmdir(p: &Path) -> io::Result<()> {
 }
 
 pub fn remove_dir_all(path: &Path) -> io::Result<()> {
+    let filetype = try!(lstat(path)).file_type();
+    if filetype.is_symlink() {
+        // On Windows symlinks to files and directories are removed differently.
+        // rmdir only deletes dir symlinks and junctions, not file symlinks.
+        rmdir(path)
+    } else {
+        remove_dir_all_recursive(path)
+    }
+}
+
+fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
     for child in try!(readdir(path)) {
         let child = try!(child);
         let child_type = try!(child.file_type());
         if child_type.is_dir() {
-            try!(remove_dir_all(&child.path()));
+            try!(remove_dir_all_recursive(&child.path()));
         } else if child_type.is_symlink_dir() {
             try!(rmdir(&child.path()));
         } else {