diff options
Diffstat (limited to 'src/devices/file/directory_listing.rs')
-rw-r--r-- | src/devices/file/directory_listing.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/devices/file/directory_listing.rs b/src/devices/file/directory_listing.rs index 1295f8b..c894306 100644 --- a/src/devices/file/directory_listing.rs +++ b/src/devices/file/directory_listing.rs @@ -30,6 +30,9 @@ impl DirectoryListing { if byte_path.len() > 255 { continue; }; + if filename_dot_prefixed(&path) { + continue; + } let metadata = continue_on_err!(std::fs::metadata(&entry.path())); children.push( DirectoryChild { byte_path: Vec::from(byte_path), @@ -106,3 +109,20 @@ pub fn remove_base(absolute_path: &Path, base_path: &Path) -> Result<PathBuf, () } return Err(()); } + +// Returns true if a dot character directly follows the right-most +// forward-slash character in the path. +fn filename_dot_prefixed(path: &Path) -> bool { + let bytes = path.as_os_str().as_bytes(); + // Find position of final forward-slash byte. + let mut final_slash = None; + for (i, byte) in bytes.iter().enumerate() { + if *byte == b'/' { final_slash = Some(i) } + } + if let Some(i) = final_slash { + if let Some(b'.') = bytes.get(i+1) { + return true; + } + } + return false; +} |