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
69
70
71
72
73
74
use crate::fs::Permissions;
use rustix::fs::RawMode;
use std::fs;
#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) struct PermissionsExt {
#[cfg(not(target_os = "wasi"))]
mode: RawMode,
}
#[cfg(not(target_os = "wasi"))]
impl PermissionsExt {
#[inline]
pub(crate) fn from_std(std: fs::Permissions) -> Self {
use std::os::unix::fs::PermissionsExt;
Self {
mode: std.mode() as RawMode,
}
}
#[inline]
pub(crate) const fn from_raw_mode(mode: RawMode) -> Permissions {
Permissions {
readonly: Self::readonly(mode),
ext: Self { mode },
}
}
#[inline]
pub(crate) const fn readonly(mode: RawMode) -> bool {
mode & 0o222 == 0
}
#[inline]
pub(crate) fn set_readonly(&mut self, readonly: bool) {
if readonly {
self.mode &= !0o222;
} else {
self.mode |= 0o222;
}
}
}
#[cfg(not(target_os = "wasi"))]
impl std::os::unix::fs::PermissionsExt for PermissionsExt {
fn mode(&self) -> u32 {
self.mode as u32
}
fn set_mode(&mut self, mode: u32) {
self.mode = mode as RawMode & 0o7777;
}
fn from_mode(mode: u32) -> Self {
Self {
mode: mode as RawMode & 0o7777,
}
}
}
#[cfg(target_os = "wasi")]
impl PermissionsExt {
pub(crate) fn default() -> Permissions {
Permissions { readonly: false }
}
}