]> git.lizzy.rs Git - rust.git/commitdiff
fs: add and test for DirectoryNotEmpty error variant
authorRalf Jung <post@ralfj.de>
Mon, 7 Mar 2022 23:30:12 +0000 (18:30 -0500)
committerRalf Jung <post@ralfj.de>
Mon, 7 Mar 2022 23:30:12 +0000 (18:30 -0500)
src/helpers.rs
src/lib.rs
tests/run-pass/fs.rs

index 2f1c74a0587ec07ba0a5aefc3836dfa7b2d020e3..cae8f5ddb4484e188a30029397e4d24a5ac4908c 100644 (file)
@@ -490,6 +490,7 @@ fn set_last_error_from_io_error(&mut self, err_kind: std::io::ErrorKind) -> Inte
                 TimedOut => "ETIMEDOUT",
                 AlreadyExists => "EEXIST",
                 WouldBlock => "EWOULDBLOCK",
+                DirectoryNotEmpty => "ENOTEMPTY",
                 _ => {
                     throw_unsup_format!(
                         "io error {:?} cannot be translated into a raw os error",
index 9542fb9b96355228e0391359d4d44dfb9c374a3e..6c9b8ee0b8f9893893398fb412e3354f22549b25 100644 (file)
@@ -5,6 +5,7 @@
 #![feature(try_blocks)]
 #![feature(let_else)]
 #![feature(bool_to_option)]
+#![feature(io_error_more)]
 #![warn(rust_2018_idioms)]
 #![allow(clippy::cast_lossless)]
 
index be680131f84ab106563aa7cff391ee38e5029638..7f5553e2f2cb90e3bea716a6c46d2df08a147c7f 100644 (file)
@@ -2,6 +2,7 @@
 // compile-flags: -Zmiri-disable-isolation
 
 #![feature(rustc_private)]
+#![feature(io_error_more)]
 
 extern crate libc;
 
@@ -380,6 +381,8 @@ fn test_directory() {
     let mut file_names = dir_iter.map(|e| e.unwrap().file_name()).collect::<Vec<_>>();
     file_names.sort_unstable();
     assert_eq!(file_names, vec!["test_file_1", "test_file_2"]);
+    // Deleting the directory should fail, since it is not empty.
+    assert_eq!(ErrorKind::DirectoryNotEmpty, remove_dir(&dir_path).unwrap_err().kind());
     // Clean up the files in the directory
     remove_file(&path_1).unwrap();
     remove_file(&path_2).unwrap();