1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Primitives for asynchronous filesystem operations.
//!
//! This module is an async version of [`std::fs`].

use std::{io::Result, path::Path};

use crate::runtime::syscall;

mod open;
pub use open::OpenOptions;

mod file;
pub use file::File;

mod metadata;
pub use metadata::Metadata;

/// An async version of [`std::fs::rename`].
pub async fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<()> {
    let from = from.as_ref();
    let to = to.as_ref();
    syscall::rename(from, to).await
}

/// An async version of [`std::fs::remove_file`].
pub async fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> {
    let path = path.as_ref();
    syscall::unlink(path).await
}

/// An async version of [`std::fs::create_dir`].
pub async fn create_dir<P: AsRef<Path>>(path: P) -> Result<()> {
    let path = path.as_ref();
    syscall::mkdir(path, 0o777).await
}

/// An async version of [`std::fs::remove_dir`].
pub async fn remove_dir<P: AsRef<Path>>(path: P) -> Result<()> {
    let path = path.as_ref();
    syscall::rmdir(path).await
}