mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-18 00:00:09 +02:00
64 lines
1.5 KiB
Rust
64 lines
1.5 KiB
Rust
#![deny(warnings, rust_2018_idioms)]
|
|
|
|
use std::fs;
|
|
use std::io::prelude::*;
|
|
use std::io::BufReader;
|
|
use tempdir::TempDir;
|
|
use tokio_fs::*;
|
|
|
|
mod pool;
|
|
|
|
#[test]
|
|
fn test_hard_link() {
|
|
let dir = TempDir::new("base").unwrap();
|
|
let src = dir.path().join("src.txt");
|
|
let dst = dir.path().join("dst.txt");
|
|
|
|
{
|
|
let mut file = fs::File::create(&src).unwrap();
|
|
file.write_all(b"hello").unwrap();
|
|
}
|
|
|
|
pool::run({ hard_link(src, dst.clone()) });
|
|
|
|
let mut content = String::new();
|
|
|
|
{
|
|
let file = fs::File::open(dst).unwrap();
|
|
let mut reader = BufReader::new(file);
|
|
reader.read_to_string(&mut content).unwrap();
|
|
}
|
|
|
|
assert!(content == "hello");
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
#[test]
|
|
fn test_symlink() {
|
|
use futures::Future;
|
|
|
|
let dir = TempDir::new("base").unwrap();
|
|
let src = dir.path().join("src.txt");
|
|
let dst = dir.path().join("dst.txt");
|
|
|
|
{
|
|
let mut file = fs::File::create(&src).unwrap();
|
|
file.write_all(b"hello").unwrap();
|
|
}
|
|
|
|
pool::run({ os::unix::symlink(src.clone(), dst.clone()) });
|
|
|
|
let mut content = String::new();
|
|
|
|
{
|
|
let file = fs::File::open(dst.clone()).unwrap();
|
|
let mut reader = BufReader::new(file);
|
|
reader.read_to_string(&mut content).unwrap();
|
|
}
|
|
|
|
assert!(content == "hello");
|
|
|
|
pool::run({ read_link(dst.clone()).map(move |x| assert!(x == src)) });
|
|
pool::run({ symlink_metadata(dst.clone()).map(move |x| assert!(x.file_type().is_symlink())) });
|
|
}
|