Skip to content

Commit 13ab796

Browse files
committed
impl From<c::WIN32_FIND_DATAW> for FileAttr
1 parent d2074cb commit 13ab796

File tree

1 file changed

+21
-16
lines changed
  • library/std/src/sys/windows

1 file changed

+21
-16
lines changed

library/std/src/sys/windows/fs.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,7 @@ impl DirEntry {
155155
}
156156

157157
pub fn metadata(&self) -> io::Result<FileAttr> {
158-
Ok(FileAttr {
159-
attributes: self.data.dwFileAttributes,
160-
creation_time: self.data.ftCreationTime,
161-
last_access_time: self.data.ftLastAccessTime,
162-
last_write_time: self.data.ftLastWriteTime,
163-
file_size: ((self.data.nFileSizeHigh as u64) << 32) | (self.data.nFileSizeLow as u64),
164-
reparse_tag: if self.data.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
165-
// reserved unless this is a reparse point
166-
self.data.dwReserved0
167-
} else {
168-
0
169-
},
170-
volume_serial_number: None,
171-
number_of_links: None,
172-
file_index: None,
173-
})
158+
Ok(self.data.into())
174159
}
175160
}
176161

@@ -879,6 +864,26 @@ impl FileAttr {
879864
self.file_index
880865
}
881866
}
867+
impl From<c::WIN32_FIND_DATAW> for FileAttr {
868+
fn from(wfd: c::WIN32_FIND_DATAW) -> Self {
869+
FileAttr {
870+
attributes: wfd.dwFileAttributes,
871+
creation_time: wfd.ftCreationTime,
872+
last_access_time: wfd.ftLastAccessTime,
873+
last_write_time: wfd.ftLastWriteTime,
874+
file_size: ((wfd.nFileSizeHigh as u64) << 32) | (wfd.nFileSizeLow as u64),
875+
reparse_tag: if wfd.dwFileAttributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 {
876+
// reserved unless this is a reparse point
877+
wfd.dwReserved0
878+
} else {
879+
0
880+
},
881+
volume_serial_number: None,
882+
number_of_links: None,
883+
file_index: None,
884+
}
885+
}
886+
}
882887

883888
fn to_u64(ft: &c::FILETIME) -> u64 {
884889
(ft.dwLowDateTime as u64) | ((ft.dwHighDateTime as u64) << 32)

0 commit comments

Comments
 (0)