Skip to content

Commit

Permalink
Only enable perm modification test for unix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo committed Feb 20, 2023
1 parent e8dbee0 commit de09cd2
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions tokio/tests/fs_try_exists.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support file operations

use std::os::unix::prelude::PermissionsExt;

use tempfile::tempdir;
use tokio::fs;

Expand All @@ -16,26 +14,30 @@ async fn try_exists() {

assert!(fs::try_exists(existing_path).await.unwrap());
assert!(!fs::try_exists(nonexisting_path).await.unwrap());
#[cfg(unix)]
{
use std::os::unix::prelude::PermissionsExt;
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();

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
);
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
);
}
}

0 comments on commit de09cd2

Please sign in to comment.