1 #![warn(rust_2018_idioms)] 2 #![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations 3 4 use tempfile::tempdir; 5 use tokio::fs; 6 7 #[tokio::test] 8 #[cfg_attr(miri, ignore)] // No `fchmod` in miri. copy()9async fn copy() { 10 let dir = tempdir().unwrap(); 11 12 let source_path = dir.path().join("foo.txt"); 13 let dest_path = dir.path().join("bar.txt"); 14 15 fs::write(&source_path, b"Hello File!").await.unwrap(); 16 fs::copy(&source_path, &dest_path).await.unwrap(); 17 18 let from = fs::read(&source_path).await.unwrap(); 19 let to = fs::read(&dest_path).await.unwrap(); 20 21 assert_eq!(from, to); 22 } 23 24 #[tokio::test] 25 #[cfg_attr(miri, ignore)] // No `fchmod` in miri. copy_permissions()26async fn copy_permissions() { 27 let dir = tempdir().unwrap(); 28 let from_path = dir.path().join("foo.txt"); 29 let to_path = dir.path().join("bar.txt"); 30 31 let from = tokio::fs::File::create(&from_path).await.unwrap(); 32 let mut from_perms = from.metadata().await.unwrap().permissions(); 33 from_perms.set_readonly(true); 34 from.set_permissions(from_perms.clone()).await.unwrap(); 35 36 tokio::fs::copy(from_path, &to_path).await.unwrap(); 37 38 let to_perms = tokio::fs::metadata(to_path).await.unwrap().permissions(); 39 40 assert_eq!(from_perms, to_perms); 41 } 42