Skip to content

Commit 4f86b8e

Browse files
committed
Auto merge of #31675 - pitdicker:fs_metadata, r=alexcrichton
Because we no longer use `GetFileAttributesExW` FileAttr is never created directly from `WIN32_FILE_ATTRIBUTE_DATA` anymore. So we should no longer store FileAttr's attributes in that c struct. r? @alexcrichton Is this what you had in mind?
2 parents 8018280 + 44e31b9 commit 4f86b8e

File tree

1 file changed

+26
-28
lines changed
  • src/libstd/sys/windows

1 file changed

+26
-28
lines changed

src/libstd/sys/windows/fs.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ pub struct File { handle: Handle }
3030

3131
#[derive(Clone)]
3232
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,
3438
reparse_tag: c::DWORD,
3539
}
3640

@@ -142,14 +146,11 @@ impl DirEntry {
142146

143147
pub fn metadata(&self) -> io::Result<FileAttr> {
144148
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),
153154
reparse_tag: if self.data.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
154155
// reserved unless this is a reparse point
155156
self.data.dwReserved0
@@ -290,14 +291,11 @@ impl File {
290291
try!(cvt(c::GetFileInformationByHandle(self.handle.raw(),
291292
&mut info)));
292293
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),
301299
reparse_tag: 0,
302300
};
303301
if attr.is_reparse_point() {
@@ -420,45 +418,45 @@ impl fmt::Debug for File {
420418

421419
impl FileAttr {
422420
pub fn size(&self) -> u64 {
423-
((self.data.nFileSizeHigh as u64) << 32) | (self.data.nFileSizeLow as u64)
421+
self.file_size
424422
}
425423

426424
pub fn perm(&self) -> FilePermissions {
427-
FilePermissions { attrs: self.data.dwFileAttributes }
425+
FilePermissions { attrs: self.attributes }
428426
}
429427

430-
pub fn attrs(&self) -> u32 { self.data.dwFileAttributes as u32 }
428+
pub fn attrs(&self) -> u32 { self.attributes as u32 }
431429

432430
pub fn file_type(&self) -> FileType {
433-
FileType::new(self.data.dwFileAttributes, self.reparse_tag)
431+
FileType::new(self.attributes, self.reparse_tag)
434432
}
435433

436434
pub fn modified(&self) -> io::Result<SystemTime> {
437-
Ok(SystemTime::from(self.data.ftLastWriteTime))
435+
Ok(SystemTime::from(self.last_write_time))
438436
}
439437

440438
pub fn accessed(&self) -> io::Result<SystemTime> {
441-
Ok(SystemTime::from(self.data.ftLastAccessTime))
439+
Ok(SystemTime::from(self.last_access_time))
442440
}
443441

444442
pub fn created(&self) -> io::Result<SystemTime> {
445-
Ok(SystemTime::from(self.data.ftCreationTime))
443+
Ok(SystemTime::from(self.creation_time))
446444
}
447445

448446
pub fn modified_u64(&self) -> u64 {
449-
to_u64(&self.data.ftLastWriteTime)
447+
to_u64(&self.last_write_time)
450448
}
451449

452450
pub fn accessed_u64(&self) -> u64 {
453-
to_u64(&self.data.ftLastAccessTime)
451+
to_u64(&self.last_access_time)
454452
}
455453

456454
pub fn created_u64(&self) -> u64 {
457-
to_u64(&self.data.ftCreationTime)
455+
to_u64(&self.creation_time)
458456
}
459457

460458
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
462460
}
463461
}
464462

0 commit comments

Comments
 (0)