1
- use crate :: fs:: { FileType , ImplFileTypeExt , MetadataExt , Permissions } ;
1
+ use crate :: fs:: { FileType , ImplFileTypeExt , ImplMetadataExt , Permissions } ;
2
2
use crate :: time:: SystemTime ;
3
3
use std:: { fs, io} ;
4
4
@@ -18,7 +18,7 @@ pub struct Metadata {
18
18
pub ( crate ) modified : Option < SystemTime > ,
19
19
pub ( crate ) accessed : Option < SystemTime > ,
20
20
pub ( crate ) created : Option < SystemTime > ,
21
- pub ( crate ) ext : MetadataExt ,
21
+ pub ( crate ) ext : ImplMetadataExt ,
22
22
}
23
23
24
24
#[ allow( clippy:: len_without_is_empty) ]
@@ -27,7 +27,7 @@ impl Metadata {
27
27
#[ inline]
28
28
pub fn from_file ( file : & fs:: File ) -> io:: Result < Self > {
29
29
let std = file. metadata ( ) ?;
30
- let ext = MetadataExt :: from ( file, & std) ?;
30
+ let ext = ImplMetadataExt :: from ( file, & std) ?;
31
31
let file_type = ImplFileTypeExt :: from ( file, & std) ?;
32
32
Ok ( Self :: from_parts ( std, ext, file_type) )
33
33
}
@@ -41,13 +41,13 @@ impl Metadata {
41
41
/// [`std::fs::Metadata::volume_serial_number`]: https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html#tymethod.volume_serial_number
42
42
#[ inline]
43
43
pub fn from_just_metadata ( std : fs:: Metadata ) -> Self {
44
- let ext = MetadataExt :: from_just_metadata ( & std) ;
44
+ let ext = ImplMetadataExt :: from_just_metadata ( & std) ;
45
45
let file_type = ImplFileTypeExt :: from_just_metadata ( & std) ;
46
46
Self :: from_parts ( std, ext, file_type)
47
47
}
48
48
49
49
#[ inline]
50
- fn from_parts ( std : fs:: Metadata , ext : MetadataExt , file_type : FileType ) -> Self {
50
+ fn from_parts ( std : fs:: Metadata , ext : ImplMetadataExt , file_type : FileType ) -> Self {
51
51
Self {
52
52
file_type,
53
53
len : std. len ( ) ,
@@ -198,129 +198,191 @@ impl Metadata {
198
198
}
199
199
}
200
200
201
+ /// Unix-specific extensions for [`MetadataExt`].
202
+ ///
203
+ /// This corresponds to [`std::os::unix::fs::MetadataExt`].
204
+ #[ cfg( any( unix, target_os = "vxworks" ) ) ]
205
+ pub trait MetadataExt {
206
+ /// Returns the ID of the device containing the file.
207
+ fn dev ( & self ) -> u64 ;
208
+ /// Returns the inode number.
209
+ fn ino ( & self ) -> u64 ;
210
+ /// Returns the rights applied to this file.
211
+ fn mode ( & self ) -> u32 ;
212
+ /// Returns the number of hard links pointing to this file.
213
+ fn nlink ( & self ) -> u64 ;
214
+ /// Returns the user ID of the owner of this file.
215
+ fn uid ( & self ) -> u32 ;
216
+ /// Returns the group ID of the owner of this file.
217
+ fn gid ( & self ) -> u32 ;
218
+ /// Returns the device ID of this file (if it is a special one).
219
+ fn rdev ( & self ) -> u64 ;
220
+ /// Returns the total size of this file in bytes.
221
+ fn size ( & self ) -> u64 ;
222
+ /// Returns the last access time of the file, in seconds since Unix Epoch.
223
+ fn atime ( & self ) -> i64 ;
224
+ /// Returns the last access time of the file, in nanoseconds since [`atime`].
225
+ fn atime_nsec ( & self ) -> i64 ;
226
+ /// Returns the last modification time of the file, in seconds since Unix Epoch.
227
+ fn mtime ( & self ) -> i64 ;
228
+ /// Returns the last modification time of the file, in nanoseconds since [`mtime`].
229
+ fn mtime_nsec ( & self ) -> i64 ;
230
+ /// Returns the last status change time of the file, in seconds since Unix Epoch.
231
+ fn ctime ( & self ) -> i64 ;
232
+ /// Returns the last status change time of the file, in nanoseconds since [`ctime`].
233
+ fn ctime_nsec ( & self ) -> i64 ;
234
+ /// Returns the block size for filesystem I/O.
235
+ fn blksize ( & self ) -> u64 ;
236
+ /// Returns the number of blocks allocated to the file, in 512-byte units.
237
+ fn blocks ( & self ) -> u64 ;
238
+ #[ cfg( target_os = "vxworks" ) ]
239
+ fn attrib ( & self ) -> u8 ;
240
+ }
241
+
242
+ /// WASI-specific extensions for [`MetadataExt`].
243
+ ///
244
+ /// This corresponds to [`std::os::wasi::fs::MetadataExt`].
245
+ #[ cfg( target_os = "wasi" ) ]
246
+ pub trait MetadataExt {
247
+ /// Returns the ID of the device containing the file.
248
+ fn dev ( & self ) -> u64 ;
249
+ /// Returns the inode number.
250
+ fn ino ( & self ) -> u64 ;
251
+ /// Returns the number of hard links pointing to this file.
252
+ fn nlink ( & self ) -> u64 ;
253
+ /// Returns the total size of this file in bytes.
254
+ fn size ( & self ) -> u64 ;
255
+ /// Returns the last access time of the file, in seconds since Unix Epoch.
256
+ fn atim ( & self ) -> u64 ;
257
+ /// Returns the last modification time of the file, in seconds since Unix Epoch.
258
+ fn mtim ( & self ) -> u64 ;
259
+ /// Returns the last status change time of the file, in seconds since Unix Epoch.
260
+ fn ctim ( & self ) -> u64 ;
261
+ }
262
+
201
263
#[ cfg( unix) ]
202
- impl std :: os :: unix :: fs :: MetadataExt for Metadata {
264
+ impl MetadataExt for Metadata {
203
265
#[ inline]
204
266
fn dev ( & self ) -> u64 {
205
- self . ext . dev ( )
267
+ rustix :: fs :: MetadataExt :: dev ( & self . ext )
206
268
}
207
269
208
270
#[ inline]
209
271
fn ino ( & self ) -> u64 {
210
- self . ext . ino ( )
272
+ rustix :: fs :: MetadataExt :: ino ( & self . ext )
211
273
}
212
274
213
275
#[ inline]
214
276
fn mode ( & self ) -> u32 {
215
- self . ext . mode ( )
277
+ rustix :: fs :: MetadataExt :: mode ( & self . ext )
216
278
}
217
279
218
280
#[ inline]
219
281
fn nlink ( & self ) -> u64 {
220
- self . ext . nlink ( )
282
+ rustix :: fs :: MetadataExt :: nlink ( & self . ext )
221
283
}
222
284
223
285
#[ inline]
224
286
fn uid ( & self ) -> u32 {
225
- self . ext . uid ( )
287
+ rustix :: fs :: MetadataExt :: uid ( & self . ext )
226
288
}
227
289
228
290
#[ inline]
229
291
fn gid ( & self ) -> u32 {
230
- self . ext . gid ( )
292
+ rustix :: fs :: MetadataExt :: gid ( & self . ext )
231
293
}
232
294
233
295
#[ inline]
234
296
fn rdev ( & self ) -> u64 {
235
- self . ext . rdev ( )
297
+ rustix :: fs :: MetadataExt :: rdev ( & self . ext )
236
298
}
237
299
238
300
#[ inline]
239
301
fn size ( & self ) -> u64 {
240
- self . ext . size ( )
302
+ rustix :: fs :: MetadataExt :: size ( & self . ext )
241
303
}
242
304
243
305
#[ inline]
244
306
fn atime ( & self ) -> i64 {
245
- self . ext . atime ( )
307
+ rustix :: fs :: MetadataExt :: atime ( & self . ext )
246
308
}
247
309
248
310
#[ inline]
249
311
fn atime_nsec ( & self ) -> i64 {
250
- self . ext . atime_nsec ( )
312
+ rustix :: fs :: MetadataExt :: atime_nsec ( & self . ext )
251
313
}
252
314
253
315
#[ inline]
254
316
fn mtime ( & self ) -> i64 {
255
- self . ext . mtime ( )
317
+ rustix :: fs :: MetadataExt :: mtime ( & self . ext )
256
318
}
257
319
258
320
#[ inline]
259
321
fn mtime_nsec ( & self ) -> i64 {
260
- self . ext . mtime_nsec ( )
322
+ rustix :: fs :: MetadataExt :: mtime_nsec ( & self . ext )
261
323
}
262
324
263
325
#[ inline]
264
326
fn ctime ( & self ) -> i64 {
265
- self . ext . ctime ( )
327
+ rustix :: fs :: MetadataExt :: ctime ( & self . ext )
266
328
}
267
329
268
330
#[ inline]
269
331
fn ctime_nsec ( & self ) -> i64 {
270
- self . ext . ctime_nsec ( )
332
+ rustix :: fs :: MetadataExt :: ctime_nsec ( & self . ext )
271
333
}
272
334
273
335
#[ inline]
274
336
fn blksize ( & self ) -> u64 {
275
- self . ext . blksize ( )
337
+ rustix :: fs :: MetadataExt :: blksize ( & self . ext )
276
338
}
277
339
278
340
#[ inline]
279
341
fn blocks ( & self ) -> u64 {
280
- self . ext . blocks ( )
342
+ rustix :: fs :: MetadataExt :: blocks ( & self . ext )
281
343
}
282
344
}
283
345
284
346
#[ cfg( target_os = "wasi" ) ]
285
- impl std :: os :: wasi :: fs :: MetadataExt for Metadata {
347
+ impl MetadataExt for Metadata {
286
348
#[ inline]
287
349
fn dev ( & self ) -> u64 {
288
- self . ext . dev ( )
350
+ rustix :: fs :: MetadataExt :: dev ( & self . ext )
289
351
}
290
352
291
353
#[ inline]
292
354
fn ino ( & self ) -> u64 {
293
- self . ext . ino ( )
355
+ rustix :: fs :: MetadataExt :: ino ( & self . ext )
294
356
}
295
357
296
358
#[ inline]
297
359
fn nlink ( & self ) -> u64 {
298
- self . ext . nlink ( )
360
+ rustix :: fs :: MetadataExt :: nlink ( & self . ext )
299
361
}
300
362
301
363
#[ inline]
302
364
fn size ( & self ) -> u64 {
303
- self . ext . size ( )
365
+ rustix :: fs :: MetadataExt :: size ( & self . ext )
304
366
}
305
367
306
368
#[ inline]
307
369
fn atim ( & self ) -> u64 {
308
- self . ext . atim ( )
370
+ rustix :: fs :: MetadataExt :: atim ( & self . ext )
309
371
}
310
372
311
373
#[ inline]
312
374
fn mtim ( & self ) -> u64 {
313
- self . ext . mtim ( )
375
+ rustix :: fs :: MetadataExt :: mtim ( & self . ext )
314
376
}
315
377
316
378
#[ inline]
317
379
fn ctim ( & self ) -> u64 {
318
- self . ext . ctim ( )
380
+ rustix :: fs :: MetadataExt :: ctim ( & self . ext )
319
381
}
320
382
}
321
383
322
384
#[ cfg( target_os = "vxworks" ) ]
323
- impl std :: os :: vxworks :: fs :: MetadataExt for Metadata {
385
+ impl MetadataExt for Metadata {
324
386
#[ inline]
325
387
fn dev ( & self ) -> u64 {
326
388
self . ext . dev ( )
@@ -403,7 +465,7 @@ impl std::os::vxworks::fs::MetadataExt for Metadata {
403
465
}
404
466
405
467
#[ cfg( all( windows, windows_by_handle) ) ]
406
- impl std :: os :: windows :: fs :: MetadataExt for Metadata {
468
+ impl MetadataExt for Metadata {
407
469
#[ inline]
408
470
fn file_attributes ( & self ) -> u32 {
409
471
self . ext . file_attributes ( )
0 commit comments