Skip to content

Commit 2ca03ca

Browse files
authored
Merge pull request #552 from hhggit/win_symlink
add os::windows::symlink_{dir,file}
2 parents 77800ab + 72ed4eb commit 2ca03ca

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/fs/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
//! This module is an async version of [`std::fs`].
44
//!
55
//! [`os::unix::fs`]: ../os/unix/fs/index.html
6+
//! [`os::windows::fs`]: ../os/windows/fs/index.html
67
//! [`std::fs`]: https://doc.rust-lang.org/std/fs/index.html
78
//!
89
//! # Platform-specific extensions
910
//!
1011
//! * Unix: use the [`os::unix::fs`] module.
12+
//! * Windows: use the [`os::windows::fs`] module.
1113
//!
1214
//! # Examples
1315
//!

src/os/windows/fs.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Windows-specific filesystem extensions.
2+
3+
use crate::io;
4+
use crate::path::Path;
5+
use crate::task::spawn_blocking;
6+
7+
/// Creates a new directory symbolic link on the filesystem.
8+
///
9+
/// The `dst` path will be a directory symbolic link pointing to the `src` path.
10+
///
11+
/// This function is an async version of [`std::os::windows::fs::symlink_dir`].
12+
///
13+
/// [`std::os::windows::fs::symlink_dir`]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_dir.html
14+
///
15+
/// # Examples
16+
///
17+
/// ```no_run
18+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
19+
/// #
20+
/// use async_std::os::windows::fs::symlink_dir;
21+
///
22+
/// symlink_dir("a", "b").await?;
23+
/// #
24+
/// # Ok(()) }) }
25+
/// ```
26+
pub async fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
27+
let src = src.as_ref().to_owned();
28+
let dst = dst.as_ref().to_owned();
29+
spawn_blocking(move || std::os::windows::fs::symlink_dir(&src, &dst)).await
30+
}
31+
32+
/// Creates a new file symbolic link on the filesystem.
33+
///
34+
/// The `dst` path will be a file symbolic link pointing to the `src` path.
35+
///
36+
/// This function is an async version of [`std::os::windows::fs::symlink_file`].
37+
///
38+
/// [`std::os::windows::fs::symlink_file`]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_file.html
39+
///
40+
/// # Examples
41+
///
42+
/// ```no_run
43+
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
44+
/// #
45+
/// use async_std::os::windows::fs::symlink_file;
46+
///
47+
/// symlink_file("a.txt", "b.txt").await?;
48+
/// #
49+
/// # Ok(()) }) }
50+
/// ```
51+
pub async fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> {
52+
let src = src.as_ref().to_owned();
53+
let dst = dst.as_ref().to_owned();
54+
spawn_blocking(move || std::os::windows::fs::symlink_file(&src, &dst)).await
55+
}

src/os/windows/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
cfg_std! {
44
pub mod io;
55
}
6+
7+
cfg_default! {
8+
pub mod fs;
9+
}

0 commit comments

Comments
 (0)