From 2c9b558d14d9125534953a596e08ed4f6d33bc5d Mon Sep 17 00:00:00 2001 From: hhggit Date: Mon, 18 Nov 2019 10:07:47 +0800 Subject: [PATCH 1/2] add os::windows::symlink_{dir,file} --- src/fs/mod.rs | 2 ++ src/os/windows/fs.rs | 55 +++++++++++++++++++++++++++++++++++++++++++ src/os/windows/mod.rs | 1 + 3 files changed, 58 insertions(+) create mode 100644 src/os/windows/fs.rs diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 4598ec84..5cf086de 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -3,11 +3,13 @@ //! This module is an async version of [`std::fs`]. //! //! [`os::unix::fs`]: ../os/unix/fs/index.html +//! [`os::windows::fs`]: ../os/windows/fs/index.html //! [`std::fs`]: https://doc.rust-lang.org/std/fs/index.html //! //! # Platform-specific extensions //! //! * Unix: use the [`os::unix::fs`] module. +//! * Windows: use the [`os::windows::fs`] module. //! //! # Examples //! diff --git a/src/os/windows/fs.rs b/src/os/windows/fs.rs new file mode 100644 index 00000000..243f3819 --- /dev/null +++ b/src/os/windows/fs.rs @@ -0,0 +1,55 @@ +//! Windows-specific filesystem extensions. + +use crate::io; +use crate::path::Path; +use crate::task::spawn_blocking; + +/// Creates a new directory symbolic link on the filesystem. +/// +/// The `dst` path will be a directory symbolic link pointing to the `src` path. +/// +/// This function is an async version of [`std::os::windows::fs::symlink_dir`]. +/// +/// [`std::os::windows::fs::symlink_dir`]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_dir.html +/// +/// # Examples +/// +/// ```no_run +/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # +/// use async_std::os::windows::fs::symlink_dir; +/// +/// symlink_dir("a", "b").await?; +/// # +/// # Ok(()) }) } +/// ``` +pub async fn symlink_dir, Q: AsRef>(src: P, dst: Q) -> io::Result<()> { + let src = src.as_ref().to_owned(); + let dst = dst.as_ref().to_owned(); + spawn_blocking(move || std::os::windows::fs::symlink_dir(&src, &dst)).await +} + +/// Creates a new file symbolic link on the filesystem. +/// +/// The `dst` path will be a file symbolic link pointing to the `src` path. +/// +/// This function is an async version of [`std::os::windows::fs::symlink_file`]. +/// +/// [`std::os::windows::fs::symlink_file`]: https://doc.rust-lang.org/std/os/windows/fs/fn.symlink_file.html +/// +/// # Examples +/// +/// ```no_run +/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { +/// # +/// use async_std::os::windows::fs::symlink_file; +/// +/// symlink_file("a.txt", "b.txt").await?; +/// # +/// # Ok(()) }) } +/// ``` +pub async fn symlink_file, Q: AsRef>(src: P, dst: Q) -> io::Result<()> { + let src = src.as_ref().to_owned(); + let dst = dst.as_ref().to_owned(); + spawn_blocking(move || std::os::windows::fs::symlink_file(&src, &dst)).await +} diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index f3350007..5f0bc0e4 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -2,4 +2,5 @@ cfg_std! { pub mod io; + pub mod fs; } From 72ed4eb4fde43ec89d7135f0d16b4df3b0d88fda Mon Sep 17 00:00:00 2001 From: hhggit Date: Wed, 20 Nov 2019 19:51:01 +0800 Subject: [PATCH 2/2] Update mod.rs --- src/os/windows/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index 5f0bc0e4..cd8deb60 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -2,5 +2,8 @@ cfg_std! { pub mod io; +} + +cfg_default! { pub mod fs; }