Sha256: 8ed69037a876312bc3d0a0ffe3e970349a3827369db5fe60d8123315f99fefae

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations

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!(fs::try_exists(existing_path).await.unwrap());
    assert!(!fs::try_exists(nonexisting_path).await.unwrap());
    // FreeBSD root user always has permission to stat.
    #[cfg(all(unix, not(target_os = "freebsd")))]
    {
        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();

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wasmtime-9.0.1 ./ext/cargo-vendor/tokio-1.28.1/tests/fs_try_exists.rs
wasmtime-8.0.0 ./ext/cargo-vendor/tokio-1.27.0/tests/fs_try_exists.rs
wasmtime-7.0.0 ./ext/cargo-vendor/tokio-1.27.0/tests/fs_try_exists.rs