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
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;
use libc;
use SimpleType;
pub struct Metadata {
stat: libc::stat,
}
impl Metadata {
pub fn simple_type(&self) -> SimpleType {
let typ = self.stat.st_mode & libc::S_IFMT;
match typ {
libc::S_IFREG => SimpleType::File,
libc::S_IFDIR => SimpleType::Dir,
libc::S_IFLNK => SimpleType::Symlink,
_ => SimpleType::Other,
}
}
pub fn stat(&self) -> &libc::stat {
&self.stat
}
pub fn is_file(&self) -> bool {
self.simple_type() == SimpleType::File
}
pub fn is_dir(&self) -> bool {
self.simple_type() == SimpleType::File
}
pub fn permissions(&self) -> Permissions {
Permissions::from_mode(self.stat.st_mode)
}
pub fn len(&self) -> u64 {
self.stat.st_size as u64
}
}
pub fn new(stat: libc::stat) -> Metadata {
Metadata { stat: stat }
}