Hide xattr errors unless --extended

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)
This commit is contained in:
Benjamin Sago 2017-08-11 12:36:14 +01:00
parent 97d1472331
commit 5189d66e2c
8 changed files with 79 additions and 19 deletions

View File

@ -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 were compiling without that feature, then
// exa pretends no files have attributes.
// 2. If the feature is enabled but the --extended flag
// hasnt been specified, then display an @ in the
// permissions column for files with xattrs, but dont
// 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 files xattrs, exa
// would display that error even though the attributes
// werent actually being shown! This was confusing, as
// users were being shown errors for something they didnt
// explicitly ask for, and just cluttered up the output.
// So now errors arent 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)) },
};
}

View File

@ -7,17 +7,12 @@
├── escape: [\u{1b}]
├── form-feed: [\u{c}]
├── invalid-utf8-1: [<5B>]
│ └── <Error: path somehow contained a NUL?>
├── invalid-utf8-2: [<5B>(]
│ └── <Error: path somehow contained a NUL?>
├── invalid-utf8-3: [<5B>(]
│ └── <Error: path somehow contained a NUL?>
├── invalid-utf8-4: [<5B>(<28>(]
│ └── <Error: path somehow contained a NUL?>
├── links
│ ├── another: [\n] -> /testcases/file-names/new-line-dir: [\n]/another: [\n]
│ ├── broken -> /testcases/file-names/new-line-dir: [\n]/broken
│ │ └── <No such file or directory (os error 2)>
│ └── subfile -> /testcases/file-names/new-line-dir: [\n]/subfile
├── new-line-dir: [\n]
│ ├── another: [\n]

29
xtests/file_names_T@ Normal file
View File

@ -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: [<5B>]
│ └── <Error: path somehow contained a NUL?>
├── invalid-utf8-2: [<5B>(]
│ └── <Error: path somehow contained a NUL?>
├── invalid-utf8-3: [<5B>(]
│ └── <Error: path somehow contained a NUL?>
├── invalid-utf8-4: [<5B>(<28>(]
│ └── <Error: path somehow contained a NUL?>
├── links
│ ├── another: [\n] -> /testcases/file-names/new-line-dir: [\n]/another: [\n]
│ ├── broken -> /testcases/file-names/new-line-dir: [\n]/broken
│ │ └── <No such file or directory (os error 2)>
│ └── 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}]

View File

@ -1,11 +1,8 @@
/testcases/links
├── broken -> nowhere
│ └── <No such file or directory (os error 2)>
├── current_dir -> .
├── forbidden -> /proc/1/root
│ └── <Permission denied (os error 13)>
├── itself -> itself
│ └── <Too many levels of symbolic links (os error 40)>
├── parent_dir -> ..
├── root -> /
├── some_file

14
xtests/links_T@ Normal file
View File

@ -0,0 +1,14 @@
/testcases/links
├── broken -> nowhere
│ └── <No such file or directory (os error 2)>
├── current_dir -> .
├── forbidden -> /proc/1/root
│ └── <Permission denied (os error 13)>
├── itself -> itself
│ └── <Too many levels of symbolic links (os error 40)>
├── parent_dir -> ..
├── root -> /
├── some_file
├── some_file_absolute -> /testcases/links/some_file
├── some_file_relative -> some_file
└── usr -> /usr

View File

@ -1,2 +1 @@
/proc/1/root
└── <Permission denied (os error 13)>

2
xtests/proc_1_root_@ Normal file
View File

@ -0,0 +1,2 @@
/proc/1/root
└── <Permission denied (os error 13)>

View File

@ -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
# Thereve been bugs where the target file wasnt printed properly when the
# symlink file was specified on the command-line directly.