tokio_fs/
set_permissions.rs

1use std::fs;
2use std::io;
3use std::path::Path;
4
5use futures::{Future, Poll};
6
7/// Changes the permissions found on a file or a directory.
8///
9/// This is an async version of [`std::fs::set_permissions`][std]
10///
11/// [std]: https://doc.rust-lang.org/std/fs/fn.set_permissions.html
12pub fn set_permissions<P: AsRef<Path>>(path: P, perm: fs::Permissions) -> SetPermissionsFuture<P> {
13    SetPermissionsFuture::new(path, perm)
14}
15
16/// Future returned by `set_permissions`.
17#[derive(Debug)]
18pub struct SetPermissionsFuture<P>
19where
20    P: AsRef<Path>,
21{
22    path: P,
23    perm: fs::Permissions,
24}
25
26impl<P> SetPermissionsFuture<P>
27where
28    P: AsRef<Path>,
29{
30    fn new(path: P, perm: fs::Permissions) -> SetPermissionsFuture<P> {
31        SetPermissionsFuture {
32            path: path,
33            perm: perm,
34        }
35    }
36}
37
38impl<P> Future for SetPermissionsFuture<P>
39where
40    P: AsRef<Path>,
41{
42    type Item = ();
43    type Error = io::Error;
44
45    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
46        ::blocking_io(|| fs::set_permissions(&self.path, self.perm.clone()))
47    }
48}