From 7643a4dd3eab1548d6878c7e62921a813cdf735a Mon Sep 17 00:00:00 2001 From: Kevin Qian Date: Mon, 20 Feb 2023 13:21:15 -0800 Subject: [PATCH] Add `fs::try_exists` --- tokio/tests/fs_try_exists.rs | 45 ------------------------------------ 1 file changed, 45 deletions(-) delete mode 100644 tokio/tests/fs_try_exists.rs diff --git a/tokio/tests/fs_try_exists.rs b/tokio/tests/fs_try_exists.rs deleted file mode 100644 index 04c359ef30d..00000000000 --- a/tokio/tests/fs_try_exists.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![warn(rust_2018_idioms)] -#![cfg(feature = "full")] - -use std::os::unix::prelude::PermissionsExt; - -use tempfile::tempdir; -use tokio::fs; - -#[tokio::test] -async fn try_exists() { - let dir = tempdir().unwrap(); - - let existing_path = dir.path().join("foo.txt"); - fs::write(&existing_path, b"Hello File!").await.unwrap(); - let nonexisting_path = dir.path().join("bar.txt"); - - assert_eq!(fs::try_exists(existing_path).await.unwrap(), true); - assert_eq!(fs::try_exists(nonexisting_path).await.unwrap(), false); - - // FreeBSD root user always has permission to stat. - #[cfg(not(freebsd))] - { - let permission_denied_directory_path = dir.path().join("baz"); - fs::create_dir(&permission_denied_directory_path) - .await - .unwrap(); - let permission_denied_file_path = permission_denied_directory_path.join("baz.txt"); - fs::write(&permission_denied_file_path, b"Hello File!") - .await - .unwrap(); - let mut perms = tokio::fs::metadata(&permission_denied_directory_path) - .await - .unwrap() - .permissions(); - perms.set_mode(0o244); - fs::set_permissions(&permission_denied_directory_path, perms) - .await - .unwrap(); - let permission_denied_result = fs::try_exists(permission_denied_file_path).await; - assert_eq!( - permission_denied_result.err().unwrap().kind(), - std::io::ErrorKind::PermissionDenied - ); - } -}