From 5189d66e2ca0be83df5ba6c05587b792a0377067 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Fri, 11 Aug 2017 12:36:14 +0100 Subject: [PATCH] Hide xattr errors unless --extended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit exa now ignores errors when checking for extended attributes when the user didn’t explicitly demand that they be checked. If a file does have xattrs, it’ll still display the @ in the permissions column; errors will now just cause the @ to be hidden instead. This changed a lot of the xtests, which were displaying the error message in a few situations. Those tests have gained @-suffixed companions so the actual error messages can still be tested. Fixes #178 (finally) --- src/output/details.rs | 23 ++++++++++++++++++++++- xtests/file_names_T | 5 ----- xtests/file_names_T@ | 29 +++++++++++++++++++++++++++++ xtests/links_T | 3 --- xtests/links_T@ | 14 ++++++++++++++ xtests/proc_1_root | 1 - xtests/proc_1_root_@ | 2 ++ xtests/run.sh | 21 ++++++++++++--------- 8 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 xtests/file_names_T@ create mode 100644 xtests/links_T@ create mode 100644 xtests/proc_1_root_@ diff --git a/src/output/details.rs b/src/output/details.rs index 87768cc..79a08d6 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -191,10 +191,31 @@ impl<'a> Render<'a> { let mut errors = Vec::new(); let mut xattrs = Vec::new(); + // There are three “levels” of extended attribute support: + // + // 1. If we’re compiling without that feature, then + // exa pretends no files have attributes. + // 2. If the feature is enabled but the --extended flag + // hasn’t been specified, then display an @ in the + // permissions column for files with xattrs, but don’t + // display anything else. + // 3. If the --extended flag *has* been specified, then + // display the @, the attributes and their lengths, + // and any errors encountered when getting them. + // + // For a while, exa took a stricter approach to (2): if + // an error occurred while checking a file’s xattrs, exa + // would display that error even though the attributes + // weren’t actually being shown! This was confusing, as + // users were being shown errors for something they didn’t + // explicitly ask for, and just cluttered up the output. + // So now errors aren’t printed unless the user passes + // --extended to signify that they want to see them. + if xattr::ENABLED { match file.path.attributes() { Ok(xs) => xattrs.extend(xs), - Err(e) => errors.push((e, None)), + Err(e) => if self.opts.xattr { errors.push((e, None)) }, }; } diff --git a/xtests/file_names_T b/xtests/file_names_T index 528e4b3..47e886f 100644 --- a/xtests/file_names_T +++ b/xtests/file_names_T @@ -7,17 +7,12 @@ ├── escape: [\u{1b}] ├── form-feed: [\u{c}] ├── invalid-utf8-1: [�] -│ └──  ├── invalid-utf8-2: [�(] -│ └──  ├── invalid-utf8-3: [�(] -│ └──  ├── invalid-utf8-4: [�(�(] -│ └──  ├── links │ ├── another: [\n] -> /testcases/file-names/new-line-dir: [\n]/another: [\n] │ ├── broken -> /testcases/file-names/new-line-dir: [\n]/broken -│ │ └──  │ └── subfile -> /testcases/file-names/new-line-dir: [\n]/subfile ├── new-line-dir: [\n] │ ├── another: [\n] diff --git a/xtests/file_names_T@ b/xtests/file_names_T@ new file mode 100644 index 0000000..528e4b3 --- /dev/null +++ b/xtests/file_names_T@ @@ -0,0 +1,29 @@ +/testcases/file-names +├── ansi: [\u{1b}[34mblue\u{1b}[0m] +├── ascii: hello +├── backspace: [\u{8}] +├── bell: [\u{7}] +├── emoji: [🆒] +├── escape: [\u{1b}] +├── form-feed: [\u{c}] +├── invalid-utf8-1: [�] +│ └──  +├── invalid-utf8-2: [�(] +│ └──  +├── invalid-utf8-3: [�(] +│ └──  +├── invalid-utf8-4: [�(�(] +│ └──  +├── links +│ ├── another: [\n] -> /testcases/file-names/new-line-dir: [\n]/another: [\n] +│ ├── broken -> /testcases/file-names/new-line-dir: [\n]/broken +│ │ └──  +│ └── subfile -> /testcases/file-names/new-line-dir: [\n]/subfile +├── new-line-dir: [\n] +│ ├── another: [\n] +│ └── subfile +├── new-line: [\n] +├── return: [\r] +├── tab: [\t] +├── utf-8: pâté +└── vertical-tab: [\u{b}] diff --git a/xtests/links_T b/xtests/links_T index 040523a..de99bdf 100644 --- a/xtests/links_T +++ b/xtests/links_T @@ -1,11 +1,8 @@ /testcases/links ├── broken -> nowhere -│ └──  ├── current_dir -> . ├── forbidden -> /proc/1/root -│ └──  ├── itself -> itself -│ └──  ├── parent_dir -> .. ├── root -> / ├── some_file diff --git a/xtests/links_T@ b/xtests/links_T@ new file mode 100644 index 0000000..040523a --- /dev/null +++ b/xtests/links_T@ @@ -0,0 +1,14 @@ +/testcases/links +├── broken -> nowhere +│ └──  +├── current_dir -> . +├── forbidden -> /proc/1/root +│ └──  +├── itself -> itself +│ └──  +├── parent_dir -> .. +├── root -> / +├── some_file +├── some_file_absolute -> /testcases/links/some_file +├── some_file_relative -> some_file +└── usr -> /usr diff --git a/xtests/proc_1_root b/xtests/proc_1_root index 5f82346..e7a5138 100644 --- a/xtests/proc_1_root +++ b/xtests/proc_1_root @@ -1,2 +1 @@ /proc/1/root -└──  diff --git a/xtests/proc_1_root_@ b/xtests/proc_1_root_@ new file mode 100644 index 0000000..5f82346 --- /dev/null +++ b/xtests/proc_1_root_@ @@ -0,0 +1,2 @@ +/proc/1/root +└──  diff --git a/xtests/run.sh b/xtests/run.sh index fecd51f..e5ed2c1 100755 --- a/xtests/run.sh +++ b/xtests/run.sh @@ -86,11 +86,12 @@ sudo -u cassowary $exa $testcases/permissions -lghR 2>&1 | diff -q - $results/pe # File names # (Mostly escaping control characters in file names) -COLUMNS=80 $exa $testcases/file-names 2>&1 | diff -q - $results/file_names || exit 1 -COLUMNS=80 $exa $testcases/file-names -x 2>&1 | diff -q - $results/file_names_x || exit 1 -COLUMNS=80 $exa $testcases/file-names -R 2>&1 | diff -q - $results/file_names_R || exit 1 - $exa $testcases/file-names -1 2>&1 | diff -q - $results/file_names_1 || exit 1 - $exa $testcases/file-names -T 2>&1 | diff -q - $results/file_names_T || exit 1 +COLUMNS=80 $exa $testcases/file-names 2>&1 | diff -q - $results/file_names || exit 1 +COLUMNS=80 $exa $testcases/file-names -x 2>&1 | diff -q - $results/file_names_x || exit 1 +COLUMNS=80 $exa $testcases/file-names -R 2>&1 | diff -q - $results/file_names_R || exit 1 + $exa $testcases/file-names -1 2>&1 | diff -q - $results/file_names_1 || exit 1 + $exa $testcases/file-names -T 2>&1 | diff -q - $results/file_names_T || exit 1 + $exa $testcases/file-names -T@ 2>&1 | diff -q - $results/file_names_T@ || exit 1 # At least make sure it handles invalid UTF-8 arguments without crashing $exa $testcases/file-names/* >/dev/null || exit 1 @@ -144,10 +145,12 @@ env LANG=ja_JP.UTF-8 $exa $testcases/dates -l | diff -q - $results/dates_jp || # Links -COLUMNS=80 $exa $testcases/links 2>&1 | diff -q - $results/links || exit 1 - $exa $testcases/links -1 2>&1 | diff -q - $results/links_1 || exit 1 - $exa $testcases/links -T 2>&1 | diff -q - $results/links_T || exit 1 - $exa /proc/1/root -T 2>&1 | diff -q - $results/proc_1_root || exit 1 +COLUMNS=80 $exa $testcases/links 2>&1 | diff -q - $results/links || exit 1 + $exa $testcases/links -1 2>&1 | diff -q - $results/links_1 || exit 1 + $exa $testcases/links -T 2>&1 | diff -q - $results/links_T || exit 1 + $exa $testcases/links -T@ 2>&1 | diff -q - $results/links_T@ || exit 1 + $exa /proc/1/root -T 2>&1 | diff -q - $results/proc_1_root || exit 1 + $exa /proc/1/root -T@ 2>&1 | diff -q - $results/proc_1_root_@ || exit 1 # There’ve been bugs where the target file wasn’t printed properly when the # symlink file was specified on the command-line directly.