From 84933fabcba6d84bc198da8396f65b83a4bfeace Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sun, 9 Jun 2024 11:14:44 +1200 Subject: Hide all dot-prefixed files from directory listings This is a temporary fix to make directories more navigable. This will be removed when Cobalt can hide dot-prefixed filenames from directory listings by itself. --- src/devices/file/directory_listing.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/devices/file/directory_listing.rs') 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 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; +} -- cgit v1.2.3-70-g09d2