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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#![stable(feature = "rust1", since = "1.0.0")]
use fs::{self, Permissions, OpenOptions};
use io;
use libc;
use os::raw::c_long;
use os::unix::raw;
use path::Path;
use sys::fs::MetadataExt as UnixMetadataExt;
use sys;
use sys_common::{FromInner, AsInner, AsInnerMut};
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const USER_READ: raw::mode_t = 0o400;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const USER_WRITE: raw::mode_t = 0o200;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const USER_EXECUTE: raw::mode_t = 0o100;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const USER_RWX: raw::mode_t = 0o700;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const GROUP_READ: raw::mode_t = 0o040;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const GROUP_WRITE: raw::mode_t = 0o020;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const GROUP_EXECUTE: raw::mode_t = 0o010;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const GROUP_RWX: raw::mode_t = 0o070;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const OTHER_READ: raw::mode_t = 0o004;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const OTHER_WRITE: raw::mode_t = 0o002;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const OTHER_EXECUTE: raw::mode_t = 0o001;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const OTHER_RWX: raw::mode_t = 0o007;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const ALL_READ: raw::mode_t = 0o444;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const ALL_WRITE: raw::mode_t = 0o222;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const ALL_EXECUTE: raw::mode_t = 0o111;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const ALL_RWX: raw::mode_t = 0o777;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const SETUID: raw::mode_t = 0o4000;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const SETGID: raw::mode_t = 0o2000;
#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")]
pub const STICKY_BIT: raw::mode_t = 0o1000;
#[stable(feature = "fs_ext", since = "1.1.0")]
pub trait PermissionsExt {
#[stable(feature = "fs_ext", since = "1.1.0")]
fn mode(&self) -> raw::mode_t;
#[stable(feature = "fs_ext", since = "1.1.0")]
fn set_mode(&mut self, mode: raw::mode_t);
#[stable(feature = "fs_ext", since = "1.1.0")]
fn from_mode(mode: raw::mode_t) -> Self;
}
#[stable(feature = "fs_ext", since = "1.1.0")]
impl PermissionsExt for Permissions {
fn mode(&self) -> raw::mode_t { self.as_inner().mode() }
fn set_mode(&mut self, mode: raw::mode_t) {
*self = FromInner::from_inner(FromInner::from_inner(mode));
}
fn from_mode(mode: raw::mode_t) -> Permissions {
FromInner::from_inner(FromInner::from_inner(mode))
}
}
#[stable(feature = "fs_ext", since = "1.1.0")]
pub trait OpenOptionsExt {
#[stable(feature = "fs_ext", since = "1.1.0")]
fn mode(&mut self, mode: raw::mode_t) -> &mut Self;
}
#[stable(feature = "fs_ext", since = "1.1.0")]
impl OpenOptionsExt for OpenOptions {
fn mode(&mut self, mode: raw::mode_t) -> &mut OpenOptions {
self.as_inner_mut().mode(mode); self
}
}
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn dev(&self) -> raw::dev_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn ino(&self) -> raw::ino_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn mode(&self) -> raw::mode_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn nlink(&self) -> raw::nlink_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn uid(&self) -> raw::uid_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn gid(&self) -> raw::gid_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn rdev(&self) -> raw::dev_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn size(&self) -> raw::off_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn atime(&self) -> raw::time_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn atime_nsec(&self) -> c_long;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn mtime(&self) -> raw::time_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn mtime_nsec(&self) -> c_long;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn ctime(&self) -> raw::time_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn ctime_nsec(&self) -> c_long;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn blksize(&self) -> raw::blksize_t;
#[stable(feature = "metadata_ext", since = "1.1.0")]
fn blocks(&self) -> raw::blkcnt_t;
}
impl MetadataExt for fs::Metadata {
fn dev(&self) -> raw::dev_t { self.as_raw_stat().st_dev as raw::dev_t }
fn ino(&self) -> raw::ino_t { self.as_raw_stat().st_ino as raw::ino_t }
fn mode(&self) -> raw::mode_t { self.as_raw_stat().st_mode as raw::mode_t }
fn nlink(&self) -> raw::nlink_t { self.as_raw_stat().st_nlink as raw::nlink_t }
fn uid(&self) -> raw::uid_t { self.as_raw_stat().st_uid as raw::uid_t }
fn gid(&self) -> raw::gid_t { self.as_raw_stat().st_gid as raw::gid_t }
fn rdev(&self) -> raw::dev_t { self.as_raw_stat().st_rdev as raw::dev_t }
fn size(&self) -> raw::off_t { self.as_raw_stat().st_size as raw::off_t }
fn atime(&self) -> raw::time_t { self.as_raw_stat().st_atime }
fn atime_nsec(&self) -> c_long { self.as_raw_stat().st_atime_nsec as c_long }
fn mtime(&self) -> raw::time_t { self.as_raw_stat().st_mtime }
fn mtime_nsec(&self) -> c_long { self.as_raw_stat().st_mtime_nsec as c_long }
fn ctime(&self) -> raw::time_t { self.as_raw_stat().st_ctime }
fn ctime_nsec(&self) -> c_long { self.as_raw_stat().st_ctime_nsec as c_long }
fn blksize(&self) -> raw::blksize_t {
self.as_raw_stat().st_blksize as raw::blksize_t
}
fn blocks(&self) -> raw::blkcnt_t {
self.as_raw_stat().st_blocks as raw::blkcnt_t
}
}
#[unstable(feature = "file_type_ext", reason = "recently added API",
issue = "27796")]
pub trait FileTypeExt {
fn is_block_device(&self) -> bool;
fn is_char_device(&self) -> bool;
fn is_fifo(&self) -> bool;
fn is_socket(&self) -> bool;
}
#[unstable(feature = "file_type_ext", reason = "recently added API",
issue = "27796")]
impl FileTypeExt for fs::FileType {
fn is_block_device(&self) -> bool { self.as_inner().is(libc::S_IFBLK) }
fn is_char_device(&self) -> bool { self.as_inner().is(libc::S_IFCHR) }
fn is_fifo(&self) -> bool { self.as_inner().is(libc::S_IFIFO) }
fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) }
}
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
pub trait DirEntryExt {
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
fn ino(&self) -> raw::ino_t;
}
impl DirEntryExt for fs::DirEntry {
fn ino(&self) -> raw::ino_t { self.as_inner().ino() }
}
#[stable(feature = "symlink", since = "1.1.0")]
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
{
sys::fs::symlink(src.as_ref(), dst.as_ref())
}
#[unstable(feature = "dir_builder", reason = "recently added API",
issue = "27710")]
pub trait DirBuilderExt {
fn mode(&mut self, mode: raw::mode_t) -> &mut Self;
}
impl DirBuilderExt for fs::DirBuilder {
fn mode(&mut self, mode: raw::mode_t) -> &mut fs::DirBuilder {
self.as_inner_mut().set_mode(mode);
self
}
}