From 6d3506adef3537c2f3b28f4121cf694971fb0b91 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 7 Mar 2022 18:30:12 -0500 Subject: [PATCH] fs: add and test for DirectoryNotEmpty error variant --- src/helpers.rs | 1 + src/lib.rs | 1 + tests/run-pass/fs.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/helpers.rs b/src/helpers.rs index 2f1c74a0587..cae8f5ddb44 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -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", diff --git a/src/lib.rs b/src/lib.rs index 9542fb9b963..6c9b8ee0b8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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)] diff --git a/tests/run-pass/fs.rs b/tests/run-pass/fs.rs index be680131f84..7f5553e2f2c 100644 --- a/tests/run-pass/fs.rs +++ b/tests/run-pass/fs.rs @@ -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::>(); 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();