Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect hidden flag on Windows #766

Merged
merged 5 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
PROJECT_NAME: lsd
PROJECT_DESC: "An ls command with a lot of pretty colors."
PROJECT_AUTH: "Peltoche <[email protected]>"
RUST_MIN_SRV: "1.62.0"
RUST_MIN_SRV: "1.64.0"

on: [push, pull_request]

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- In keeping with the coreutils change, add quotes and escapes for necessary filenames from [merelymyself](https://github.com/merelymyself)
- Add support for icon theme from [zwpaper](https://github.com/zwpaper)
- Add icon for kt and kts from [LeeWeeder](https://github.com/LeeWeeder)
- Add `--system-protected` to include files with the Windows `system` flag set,
on other platform the same as `--all` [#752](https://github.com/Peltoche/lsd/issues/752)

### Fixed
- Do not quote filename when piping into another program from [TeamTamoad](https://github.com/TeamTamoad)
- Respect `hidden` flag on Windows [#752](https://github.com/Peltoche/lsd/issues/752)

## [0.23.1] - 2022-09-13

Expand Down
69 changes: 63 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ users = "0.11.*"
xattr = "0.2.*"

[target.'cfg(windows)'.dependencies]
winapi = {version = "0.3.*", features = ["aclapi", "accctrl", "winnt", "winerror", "securitybaseapi", "winbase"]}
windows = { version = "0.43.0", features = ["Win32_Foundation", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_Memory"] }

[dependencies.clap]
features = ["suggestions", "color", "wrap_help"]
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ include!("src/app.rs");

fn main() {
// rustc version too small or can't figure it out
if version_check::is_min_version("1.62.0") != Some(true) {
eprintln!("'lsd' requires rustc >= 1.62.0");
if version_check::is_min_version("1.64.0") != Some(true) {
eprintln!("'lsd' requires rustc >= 1.64.0");
exit(1);
}

Expand Down
6 changes: 6 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
22 changes: 22 additions & 0 deletions src/flags/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down Expand Up @@ -63,6 +71,20 @@ mod test {
assert_eq!(None, Display::from_arg_matches(&matches));
}

#[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"];
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern crate yaml_rust;
extern crate users;

#[cfg(windows)]
extern crate winapi;
extern crate windows;

mod app;
mod color;
Expand Down
23 changes: 20 additions & 3 deletions src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -109,8 +111,23 @@ impl Meta {
continue;
}

if flags.display == Display::VisibleOnly && name.to_string_lossy().starts_with('.') {
continue;
#[cfg(windows)]
let is_hidden =
name.to_string_lossy().starts_with('.') || windows_utils::is_path_hidden(&path);
#[cfg(not(windows))]
let is_hidden = name.to_string_lossy().starts_with('.');

#[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) {
Expand Down
Loading