summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-06-09 11:14:44 +1200
committerBen Bridle <bridle.benjamin@gmail.com>2024-06-09 11:14:44 +1200
commit84933fabcba6d84bc198da8396f65b83a4bfeace (patch)
tree87642ce05c866cc88073124bad51319d03c4f08d
parente80aa38c10f9e08d70ef2e4bf130a779c1c6a84e (diff)
downloadbedrock-pc-84933fabcba6d84bc198da8396f65b83a4bfeace.zip
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.
-rw-r--r--src/devices/file/directory_listing.rs20
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;
+}