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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use glob::glob;
use nc::Errno;
use std::path::PathBuf;
use std::result::Result;
use crate::core::env::expand_env;
pub struct RmOptions {
pub recursive: bool,
pub preserve_root: bool,
pub one_file_system: bool,
pub empty_dir: bool,
pub expand_env: bool,
pub use_glob: bool,
}
impl RmOptions {
pub fn new() -> Self {
RmOptions::default()
}
}
impl Default for RmOptions {
fn default() -> Self {
RmOptions {
recursive: false,
preserve_root: true,
one_file_system: false,
empty_dir: false,
expand_env: true,
use_glob: true,
}
}
}
pub fn rm<T: AsRef<str>>(path: T, options: &RmOptions) -> Result<(), Errno> {
let path = if options.expand_env {
expand_env(path)
} else {
path.as_ref().to_string()
};
let path_list: Vec<PathBuf> = if options.use_glob {
glob(&path).unwrap().filter_map(Result::ok).collect()
} else {
vec![PathBuf::from(path)]
};
return Ok(());
}
fn do_rm() {}