async_std/fs/
set_permissions.rs

1use crate::fs::Permissions;
2use crate::io;
3use crate::path::Path;
4use crate::task::spawn_blocking;
5
6/// Changes the permissions of a file or directory.
7///
8/// This function is an async version of [`std::fs::set_permissions`].
9///
10/// [`std::fs::set_permissions`]: https://doc.rust-lang.org/std/fs/fn.set_permissions.html
11///
12/// # Errors
13///
14/// An error will be returned in the following situations:
15///
16/// * `path` does not point to an existing file or directory.
17/// * The current process lacks permissions to change attributes on the file or directory.
18/// * Some other I/O error occurred.
19///
20/// # Examples
21///
22/// ```no_run
23/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
24/// #
25/// use async_std::fs;
26///
27/// let mut perm = fs::metadata("a.txt").await?.permissions();
28/// perm.set_readonly(true);
29/// fs::set_permissions("a.txt", perm).await?;
30/// #
31/// # Ok(()) }) }
32/// ```
33pub async fn set_permissions<P: AsRef<Path>>(path: P, perm: Permissions) -> io::Result<()> {
34    let path = path.as_ref().to_owned();
35    spawn_blocking(move || std::fs::set_permissions(path, perm)).await
36}