@@ -30,7 +30,11 @@ pub struct File { handle: Handle }
30
30
31
31
#[ derive( Clone ) ]
32
32
pub struct FileAttr {
33
- data : c:: WIN32_FILE_ATTRIBUTE_DATA ,
33
+ attributes : c:: DWORD ,
34
+ creation_time : c:: FILETIME ,
35
+ last_access_time : c:: FILETIME ,
36
+ last_write_time : c:: FILETIME ,
37
+ file_size : u64 ,
34
38
reparse_tag : c:: DWORD ,
35
39
}
36
40
@@ -142,14 +146,11 @@ impl DirEntry {
142
146
143
147
pub fn metadata ( & self ) -> io:: Result < FileAttr > {
144
148
Ok ( FileAttr {
145
- data : c:: WIN32_FILE_ATTRIBUTE_DATA {
146
- dwFileAttributes : self . data . dwFileAttributes ,
147
- ftCreationTime : self . data . ftCreationTime ,
148
- ftLastAccessTime : self . data . ftLastAccessTime ,
149
- ftLastWriteTime : self . data . ftLastWriteTime ,
150
- nFileSizeHigh : self . data . nFileSizeHigh ,
151
- nFileSizeLow : self . data . nFileSizeLow ,
152
- } ,
149
+ attributes : self . data . dwFileAttributes ,
150
+ creation_time : self . data . ftCreationTime ,
151
+ last_access_time : self . data . ftLastAccessTime ,
152
+ last_write_time : self . data . ftLastWriteTime ,
153
+ file_size : ( ( self . data . nFileSizeHigh as u64 ) << 32 ) | ( self . data . nFileSizeLow as u64 ) ,
153
154
reparse_tag : if self . data . dwFileAttributes & c:: FILE_ATTRIBUTE_REPARSE_POINT != 0 {
154
155
// reserved unless this is a reparse point
155
156
self . data . dwReserved0
@@ -290,14 +291,11 @@ impl File {
290
291
try!( cvt ( c:: GetFileInformationByHandle ( self . handle . raw ( ) ,
291
292
& mut info) ) ) ;
292
293
let mut attr = FileAttr {
293
- data : c:: WIN32_FILE_ATTRIBUTE_DATA {
294
- dwFileAttributes : info. dwFileAttributes ,
295
- ftCreationTime : info. ftCreationTime ,
296
- ftLastAccessTime : info. ftLastAccessTime ,
297
- ftLastWriteTime : info. ftLastWriteTime ,
298
- nFileSizeHigh : info. nFileSizeHigh ,
299
- nFileSizeLow : info. nFileSizeLow ,
300
- } ,
294
+ attributes : info. dwFileAttributes ,
295
+ creation_time : info. ftCreationTime ,
296
+ last_access_time : info. ftLastAccessTime ,
297
+ last_write_time : info. ftLastWriteTime ,
298
+ file_size : ( ( info. nFileSizeHigh as u64 ) << 32 ) | ( info. nFileSizeLow as u64 ) ,
301
299
reparse_tag : 0 ,
302
300
} ;
303
301
if attr. is_reparse_point ( ) {
@@ -420,45 +418,45 @@ impl fmt::Debug for File {
420
418
421
419
impl FileAttr {
422
420
pub fn size ( & self ) -> u64 {
423
- ( ( self . data . nFileSizeHigh as u64 ) << 32 ) | ( self . data . nFileSizeLow as u64 )
421
+ self . file_size
424
422
}
425
423
426
424
pub fn perm ( & self ) -> FilePermissions {
427
- FilePermissions { attrs : self . data . dwFileAttributes }
425
+ FilePermissions { attrs : self . attributes }
428
426
}
429
427
430
- pub fn attrs ( & self ) -> u32 { self . data . dwFileAttributes as u32 }
428
+ pub fn attrs ( & self ) -> u32 { self . attributes as u32 }
431
429
432
430
pub fn file_type ( & self ) -> FileType {
433
- FileType :: new ( self . data . dwFileAttributes , self . reparse_tag )
431
+ FileType :: new ( self . attributes , self . reparse_tag )
434
432
}
435
433
436
434
pub fn modified ( & self ) -> io:: Result < SystemTime > {
437
- Ok ( SystemTime :: from ( self . data . ftLastWriteTime ) )
435
+ Ok ( SystemTime :: from ( self . last_write_time ) )
438
436
}
439
437
440
438
pub fn accessed ( & self ) -> io:: Result < SystemTime > {
441
- Ok ( SystemTime :: from ( self . data . ftLastAccessTime ) )
439
+ Ok ( SystemTime :: from ( self . last_access_time ) )
442
440
}
443
441
444
442
pub fn created ( & self ) -> io:: Result < SystemTime > {
445
- Ok ( SystemTime :: from ( self . data . ftCreationTime ) )
443
+ Ok ( SystemTime :: from ( self . creation_time ) )
446
444
}
447
445
448
446
pub fn modified_u64 ( & self ) -> u64 {
449
- to_u64 ( & self . data . ftLastWriteTime )
447
+ to_u64 ( & self . last_write_time )
450
448
}
451
449
452
450
pub fn accessed_u64 ( & self ) -> u64 {
453
- to_u64 ( & self . data . ftLastAccessTime )
451
+ to_u64 ( & self . last_access_time )
454
452
}
455
453
456
454
pub fn created_u64 ( & self ) -> u64 {
457
- to_u64 ( & self . data . ftCreationTime )
455
+ to_u64 ( & self . creation_time )
458
456
}
459
457
460
458
fn is_reparse_point ( & self ) -> bool {
461
- self . data . dwFileAttributes & c:: FILE_ATTRIBUTE_REPARSE_POINT != 0
459
+ self . attributes & c:: FILE_ATTRIBUTE_REPARSE_POINT != 0
462
460
}
463
461
}
464
462
0 commit comments