summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIcxolu <10486322+Icxolu@users.noreply.github.com>2022-11-10 21:45:25 +0100
committerAbin Simon <abinsimon10@gmail.com>2022-11-13 22:10:58 +0530
commit457d4951b8491afefc29b529a000564e682a77a0 (patch)
tree54ff8a2683fa6777428ee8d6105f708f88d19dc2
parent62addc53e68193ef384e065ef15623276ab0aed8 (diff)
hide system protected files even with --all / --almost-all
since interaction with these files is rare. Introduce --system-protected flag to include these files.
-rw-r--r--src/app.rs6
-rw-r--r--src/flags/display.rs22
-rw-r--r--src/meta/mod.rs18
-rw-r--r--src/meta/windows_utils.rs11
4 files changed, 53 insertions, 4 deletions
diff --git a/src/app.rs b/src/app.rs
index 971d013..137a5e6 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -348,6 +348,12 @@ pub fn build() -> App<'static> {
.long("header")
.help("Display block headers"),
)
+ .arg(
+ Arg::with_name("system-protected")
+ .long("system-protected")
+ .help("Includes files with the windows system protection flag set. This is the same as --all on other platforms")
+ .hide(!cfg!(windows)),
+ )
}
fn validate_date_argument(arg: &str) -> Result<(), String> {
diff --git a/src/flags/display.rs b/src/flags/display.rs
index 96850db..2ac5f69 100644
--- a/src/flags/display.rs
+++ b/src/flags/display.rs
@@ -12,6 +12,8 @@ use serde::Deserialize;
#[derive(Clone, Debug, Copy, PartialEq, Eq, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
pub enum Display {
+ /// windows only, used to show files with system protected flag
+ SystemProtected,
All,
AlmostAll,
DirectoryOnly,
@@ -32,6 +34,12 @@ impl Configurable<Self> for Display {
Some(Self::AlmostAll)
} else if matches.is_present("all") {
Some(Self::All)
+ } else if matches.is_present("system-protected") {
+ #[cfg(windows)]
+ return Some(Self::SystemProtected);
+
+ #[cfg(not(windows))]
+ return Some(Self::All);
} else {
None
}
@@ -64,6 +72,20 @@ mod test {
}
#[test]
+ fn test_from_arg_matches_system_protected() {
+ let argv = ["lsd", "--system-protected"];
+ let matches = app::build().get_matches_from_safe(argv).unwrap();
+ #[cfg(windows)]
+ assert_eq!(
+ Some(Display::SystemProtected),
+ Display::from_arg_matches(&matches)
+ );
+
+ #[cfg(not(windows))]
+ assert_eq!(Some(Display::All), Display::from_arg_matches(&matches));
+ }
+
+ #[test]
fn test_from_arg_matches_all() {
let argv = ["lsd", "--all"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
diff --git a/src/meta/mod.rs b/src/meta/mod.rs
index 744ade4..aaa3ff5 100644
--- a/src/meta/mod.rs
+++ b/src/meta/mod.rs
@@ -83,7 +83,9 @@ impl Meta {
let mut content: Vec<Meta> = Vec::new();
- if Display::All == flags.display && flags.layout != Layout::Tree {
+ if matches!(flags.display, Display::All | Display::SystemProtected)
+ && flags.layout != Layout::Tree
+ {
let mut current_meta = self.clone();
current_meta.name.name = ".".to_owned();
@@ -115,9 +117,17 @@ impl Meta {
#[cfg(not(windows))]
let is_hidden = name.to_string_lossy().starts_with('.');
- // TODO: skip windows hidded
- if flags.display == Display::VisibleOnly && is_hidden {
- continue;
+ #[cfg(windows)]
+ let is_system = windows_utils::is_path_system(&path);
+ #[cfg(not(windows))]
+ let is_system = false;
+
+ match flags.display {
+ // show hidden files, but ignore system protected files
+ Display::All | Display::AlmostAll if is_system => continue,
+ // ignore hidden and system protected files
+ Display::VisibleOnly if is_hidden || is_system => continue,
+ _ => {}
}
let mut entry_meta = match Self::from_path(&path, flags.dereference.0) {
diff --git a/src/meta/windows_utils.rs b/src/meta/windows_utils.rs
index 487dc99..b2f6e27 100644
--- a/src/meta/windows_utils.rs
+++ b/src/meta/windows_utils.rs
@@ -332,6 +332,17 @@ pub fn is_path_hidden(path: &Path) -> bool {
)
}
+/// Checks whether the windows [`system`] attribute is set for the given
+/// [`Path`]
+///
+/// [`system`]: windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_SYSTEM
+pub fn is_path_system(path: &Path) -> bool {
+ has_path_attribute(
+ path,
+ windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_SYSTEM,
+ )
+}
+
#[cfg(test)]
mod test {
use super::*;