(path: &Path, include_hidden: bool)
| 15 | }; |
| 16 | |
| 17 | pub fn read_dir(path: &Path, include_hidden: bool) -> ResultType<FileDirectory> { |
| 18 | let mut dir = FileDirectory { |
| 19 | path: get_string(path), |
| 20 | ..Default::default() |
| 21 | }; |
| 22 | #[cfg(windows)] |
| 23 | if "/" == &get_string(path) { |
| 24 | let drives = unsafe { winapi::um::fileapi::GetLogicalDrives() }; |
| 25 | for i in 0..32 { |
| 26 | if drives & (1 << i) != 0 { |
| 27 | let name = format!( |
| 28 | "{}:", |
| 29 | std::char::from_u32('A' as u32 + i as u32).unwrap_or('A') |
| 30 | ); |
| 31 | dir.entries.push(FileEntry { |
| 32 | name, |
| 33 | entry_type: FileType::DirDrive.into(), |
| 34 | ..Default::default() |
| 35 | }); |
| 36 | } |
| 37 | } |
| 38 | return Ok(dir); |
| 39 | } |
| 40 | for entry in path.read_dir()?.flatten() { |
| 41 | let p = entry.path(); |
| 42 | let name = p |
| 43 | .file_name() |
| 44 | .map(|p| p.to_str().unwrap_or("")) |
| 45 | .unwrap_or("") |
| 46 | .to_owned(); |
| 47 | if name.is_empty() { |
| 48 | continue; |
| 49 | } |
| 50 | let mut is_hidden = false; |
| 51 | let meta; |
| 52 | if let Ok(tmp) = std::fs::symlink_metadata(&p) { |
| 53 | meta = tmp; |
| 54 | } else { |
| 55 | continue; |
| 56 | } |
| 57 | // docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants |
| 58 | #[cfg(windows)] |
| 59 | if meta.file_attributes() & 0x2 != 0 { |
| 60 | is_hidden = true; |
| 61 | } |
| 62 | #[cfg(not(windows))] |
| 63 | if name.find('.').unwrap_or(usize::MAX) == 0 { |
| 64 | is_hidden = true; |
| 65 | } |
| 66 | if is_hidden && !include_hidden { |
| 67 | continue; |
| 68 | } |
| 69 | let (entry_type, size) = { |
| 70 | if p.is_dir() { |
| 71 | if meta.file_type().is_symlink() { |
| 72 | (FileType::DirLink.into(), 0) |
| 73 | } else { |
| 74 | (FileType::Dir.into(), 0) |
no test coverage detected