Fix Clippy lints

This commit is contained in:
ariasuni 2020-04-19 06:33:42 +02:00
parent 5a84953b4e
commit dba3f37b0a
14 changed files with 186 additions and 199 deletions

View File

@ -50,9 +50,10 @@ fn write_statics() -> IOResult<()> {
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
let ver = match is_development_version() { let ver = if is_development_version() {
true => format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date()), format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date())
false => format!("exa v{}", cargo_version()), } else {
format!("exa v{}", cargo_version())
}; };
let out = PathBuf::from(env::var("OUT_DIR").unwrap()); let out = PathBuf::from(env::var("OUT_DIR").unwrap());

View File

@ -3,7 +3,6 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Mutex; use std::sync::Mutex;
use git2;
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use crate::fs::fields as f; use crate::fs::fields as f;

View File

@ -2,6 +2,7 @@
#![allow(trivial_casts)] // for ARM #![allow(trivial_casts)] // for ARM
extern crate libc; extern crate libc;
use std::cmp::Ordering;
use std::io; use std::io;
use std::path::Path; use std::path::Path;
@ -58,44 +59,44 @@ pub fn list_attrs(lister: &lister::Lister, path: &Path) -> io::Result<Vec<Attrib
None => return Err(io::Error::new(io::ErrorKind::Other, "Error: path somehow contained a NUL?")), None => return Err(io::Error::new(io::ErrorKind::Other, "Error: path somehow contained a NUL?")),
}; };
let mut names = Vec::new();
let bufsize = lister.listxattr_first(&c_path); let bufsize = lister.listxattr_first(&c_path);
match bufsize.cmp(&0) {
if bufsize < 0 { Ordering::Less => return Err(io::Error::last_os_error()),
return Err(io::Error::last_os_error()); Ordering::Equal => return Ok(Vec::new()),
Ordering::Greater => {},
} }
else if bufsize > 0 {
let mut buf = vec![0u8; bufsize as usize];
let err = lister.listxattr_second(&c_path, &mut buf, bufsize);
if err < 0 { let mut buf = vec![0u8; bufsize as usize];
return Err(io::Error::last_os_error()); let err = lister.listxattr_second(&c_path, &mut buf, bufsize);
}
if err > 0 { match err.cmp(&0) {
// End indices of the attribute names Ordering::Less => return Err(io::Error::last_os_error()),
// the buffer contains 0-terminated c-strings Ordering::Equal => return Ok(Vec::new()),
let idx = buf.iter().enumerate().filter_map(|(i, v)| Ordering::Greater => {},
if *v == 0 { Some(i) } else { None } }
);
let mut start = 0;
for end in idx { let mut names = Vec::new();
let c_end = end + 1; // end of the c-string (including 0) if err > 0 {
let size = lister.getxattr(&c_path, &buf[start..c_end]); // End indices of the attribute names
// the buffer contains 0-terminated c-strings
let idx = buf.iter().enumerate().filter_map(|(i, v)|
if *v == 0 { Some(i) } else { None }
);
let mut start = 0;
if size > 0 { for end in idx {
names.push(Attribute { let c_end = end + 1; // end of the c-string (including 0)
name: lister.translate_attribute_name(&buf[start..end]), let size = lister.getxattr(&c_path, &buf[start..c_end]);
size: size as usize
});
}
start = c_end; if size > 0 {
names.push(Attribute {
name: lister.translate_attribute_name(&buf[start..end]),
size: size as usize
});
} }
start = c_end;
} }
} }
Ok(names) Ok(names)
} }

View File

@ -474,8 +474,6 @@ impl<'dir> FileTarget<'dir> {
/// More readable aliases for the permission bits exposed by libc. /// More readable aliases for the permission bits exposed by libc.
#[allow(trivial_numeric_casts)] #[allow(trivial_numeric_casts)]
mod modes { mod modes {
use libc;
pub type Mode = u32; pub type Mode = u32;
// The `libc::mode_t` types actual type varies, but the value returned // The `libc::mode_t` types actual type varies, but the value returned
// from `metadata.permissions().mode()` is always `u32`. // from `metadata.permissions().mode()` is always `u32`.

View File

@ -5,9 +5,6 @@ use std::iter::FromIterator;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::path::Path; use std::path::Path;
use glob;
use natord;
use crate::fs::File; use crate::fs::File;
use crate::fs::DotFilter; use crate::fs::DotFilter;

View File

@ -2,8 +2,6 @@ use std::ffi::OsString;
use std::fmt; use std::fmt;
use std::num::ParseIntError; use std::num::ParseIntError;
use glob;
use crate::options::{flags, HelpString, VersionString}; use crate::options::{flags, HelpString, VersionString};
use crate::options::parser::{Arg, Flag, ParseError}; use crate::options::parser::{Arg, Flag, ParseError};

View File

@ -267,7 +267,7 @@ impl Args {
// -abx => error // -abx => error
// //
else { else {
for (index, byte) in bytes.into_iter().enumerate().skip(1) { for (index, byte) in bytes.iter().enumerate().skip(1) {
let arg = self.lookup_short(*byte)?; let arg = self.lookup_short(*byte)?;
let flag = Flag::Short(*byte); let flag = Flag::Short(*byte);
match arg.takes_value { match arg.takes_value {
@ -283,7 +283,7 @@ impl Args {
} }
else { else {
match arg.takes_value { match arg.takes_value {
Forbidden => assert!(false), Forbidden => unreachable!(),
Necessary(_) => { Necessary(_) => {
return Err(ParseError::NeedsValue { flag, values }); return Err(ParseError::NeedsValue { flag, values });
}, },
@ -292,7 +292,6 @@ impl Args {
} }
} }
} }
} }
} }
} }
@ -309,14 +308,14 @@ impl Args {
} }
fn lookup_short(&self, short: ShortArg) -> Result<&Arg, ParseError> { fn lookup_short(&self, short: ShortArg) -> Result<&Arg, ParseError> {
match self.0.into_iter().find(|arg| arg.short == Some(short)) { match self.0.iter().find(|arg| arg.short == Some(short)) {
Some(arg) => Ok(arg), Some(arg) => Ok(arg),
None => Err(ParseError::UnknownShortArgument { attempt: short }) None => Err(ParseError::UnknownShortArgument { attempt: short })
} }
} }
fn lookup_long<'b>(&self, long: &'b OsStr) -> Result<&Arg, ParseError> { fn lookup_long<'b>(&self, long: &'b OsStr) -> Result<&Arg, ParseError> {
match self.0.into_iter().find(|arg| arg.long == long) { match self.0.iter().find(|arg| arg.long == long) {
Some(arg) => Ok(arg), Some(arg) => Ok(arg),
None => Err(ParseError::UnknownArgument { attempt: long.to_os_string() }) None => Err(ParseError::UnknownArgument { attempt: long.to_os_string() })
} }

View File

@ -1,5 +1,4 @@
use ansi_term::Style; use ansi_term::Style;
use glob;
use crate::fs::File; use crate::fs::File;
use crate::options::{flags, Vars, Misfire}; use crate::options::{flags, Vars, Misfire};
@ -366,7 +365,7 @@ mod customs_test {
#[test] #[test]
fn $name() { fn $name() {
let mappings: Vec<(glob::Pattern, Style)> let mappings: Vec<(glob::Pattern, Style)>
= $mappings.into_iter() = $mappings.iter()
.map(|t| (glob::Pattern::new(t.0).unwrap(), t.1)) .map(|t| (glob::Pattern::new(t.0).unwrap(), t.1))
.collect(); .collect();

View File

@ -290,7 +290,7 @@ impl TimeFormat {
Ok(TimeFormat::FullISO) Ok(TimeFormat::FullISO)
} }
else { else {
Err(Misfire::BadArgument(&flags::TIME_STYLE, word.into())) Err(Misfire::BadArgument(&flags::TIME_STYLE, word))
} }
} }
} }

View File

@ -50,7 +50,7 @@ impl<'a> Render<'a> {
}; };
grid.add(tg::Cell { grid.add(tg::Cell {
contents: format!("{icon}{filename}", icon=&icon.unwrap_or("".to_string()), filename=filename.strings().to_string()), contents: format!("{icon}{filename}", icon=&icon.unwrap_or_default(), filename=filename.strings().to_string()),
width: *width, width: *width,
}); });
} }

View File

@ -46,149 +46,147 @@ fn icon(file: &File) -> char {
let extensions = Box::new(FileExtensions); let extensions = Box::new(FileExtensions);
if file.is_directory() { '\u{f115}' } if file.is_directory() { '\u{f115}' }
else if let Some(icon) = extensions.icon_file(file) { icon } else if let Some(icon) = extensions.icon_file(file) { icon }
else { else if let Some(ext) = file.ext.as_ref() {
if let Some(ext) = file.ext.as_ref() { match ext.as_str() {
match ext.as_str() { "ai" => '\u{e7b4}',
"ai" => '\u{e7b4}', "android" => '\u{e70e}',
"android" => '\u{e70e}', "apple" => '\u{f179}',
"apple" => '\u{f179}', "avro" => '\u{e60b}',
"avro" => '\u{e60b}', "clj" => '\u{e768}',
"clj" => '\u{e768}', "coffee" => '\u{f0f4}',
"coffee" => '\u{f0f4}', "cpp" => '\u{e61d}',
"cpp" => '\u{e61d}', "hpp" => '\u{e61d}',
"hpp" => '\u{e61d}', "c" => '\u{e61e}',
"c" => '\u{e61e}', "h" => '\u{e61e}',
"h" => '\u{e61e}', "cs" => '\u{f81a}',
"cs" => '\u{f81a}', "css" => '\u{e749}',
"css" => '\u{e749}', "d" => '\u{e7af}',
"d" => '\u{e7af}', "dart" => '\u{e798}',
"dart" => '\u{e798}', "db" => '\u{f1c0}',
"db" => '\u{f1c0}', "diff" => '\u{f440}',
"diff" => '\u{f440}', "patch" => '\u{f440}',
"patch" => '\u{f440}', "rtf" => '\u{f1c2}',
"rtf" => '\u{f1c2}', "doc" => '\u{f1c2}',
"doc" => '\u{f1c2}', "docx" => '\u{f1c2}',
"docx" => '\u{f1c2}', "odt" => '\u{f1c2}',
"odt" => '\u{f1c2}', "ebook" => '\u{e28b}',
"ebook" => '\u{e28b}', "env" => '\u{f462}',
"env" => '\u{f462}', "epub" => '\u{e28a}',
"epub" => '\u{e28a}', "erl" => '\u{e7b1}',
"erl" => '\u{e7b1}', "font" => '\u{f031}',
"font" => '\u{f031}', "gform" => '\u{f298}',
"gform" => '\u{f298}', "git" => '\u{f1d3}',
"git" => '\u{f1d3}', "go" => '\u{e626}',
"go" => '\u{e626}', "hs" => '\u{e777}',
"hs" => '\u{e777}', "htm" => '\u{f13b}',
"htm" => '\u{f13b}', "html" => '\u{f13b}',
"html" => '\u{f13b}', "xhtml" => '\u{f13b}',
"xhtml" => '\u{f13b}', "iml" => '\u{e7b5}',
"iml" => '\u{e7b5}', "java" => '\u{e204}',
"java" => '\u{e204}', "js" => '\u{e74e}',
"js" => '\u{e74e}', "mjs" => '\u{e74e}',
"mjs" => '\u{e74e}', "json" => '\u{e60b}',
"json" => '\u{e60b}', "jsx" => '\u{e7ba}',
"jsx" => '\u{e7ba}', "vue" => '\u{fd42}',
"vue" => '\u{fd42}', "node" => '\u{f898}',
"node" => '\u{f898}', "less" => '\u{e758}',
"less" => '\u{e758}', "log" => '\u{f18d}',
"log" => '\u{f18d}', "lua" => '\u{e620}',
"lua" => '\u{e620}', "md" => '\u{f48a}',
"md" => '\u{f48a}', "markdown" => '\u{f48a}',
"markdown" => '\u{f48a}', "mustache" => '\u{e60f}',
"mustache" => '\u{e60f}', "npmignore" => '\u{e71e}',
"npmignore" => '\u{e71e}', "pdf" => '\u{f1c1}',
"pdf" => '\u{f1c1}', "djvu" => '\u{f02d}',
"djvu" => '\u{f02d}', "mobi" => '\u{f02d}',
"mobi" => '\u{f02d}', "php" => '\u{e73d}',
"php" => '\u{e73d}', "pl" => '\u{e769}',
"pl" => '\u{e769}', "ppt" => '\u{f1c4}',
"ppt" => '\u{f1c4}', "pptx" => '\u{f1c4}',
"pptx" => '\u{f1c4}', "odp" => '\u{f1c4}',
"odp" => '\u{f1c4}', "psd" => '\u{e7b8}',
"psd" => '\u{e7b8}', "py" => '\u{e606}',
"py" => '\u{e606}', "r" => '\u{f25d}',
"r" => '\u{f25d}', "rb" => '\u{e21e}',
"rb" => '\u{e21e}', "ru" => '\u{e21e}',
"ru" => '\u{e21e}', "erb" => '\u{e21e}',
"erb" => '\u{e21e}', "gem" => '\u{e21e}',
"gem" => '\u{e21e}', "rdb" => '\u{e76d}',
"rdb" => '\u{e76d}', "rs" => '\u{e7a8}',
"rs" => '\u{e7a8}', "rss" => '\u{f09e}',
"rss" => '\u{f09e}', "rubydoc" => '\u{e73b}',
"rubydoc" => '\u{e73b}', "sass" => '\u{e74b}',
"sass" => '\u{e74b}', "stylus" => '\u{e759}',
"stylus" => '\u{e759}', "scala" => '\u{e737}',
"scala" => '\u{e737}', "shell" => '\u{f489}',
"shell" => '\u{f489}', "sqlite3" => '\u{e7c4}',
"sqlite3" => '\u{e7c4}', "styl" => '\u{e600}',
"styl" => '\u{e600}', "latex" => '\u{e600}',
"latex" => '\u{e600}', "tex" => '\u{e600}',
"tex" => '\u{e600}', "ts" => '\u{e628}',
"ts" => '\u{e628}', "tsx" => '\u{e628}',
"tsx" => '\u{e628}', "twig" => '\u{e61c}',
"twig" => '\u{e61c}', "txt" => '\u{f15c}',
"txt" => '\u{f15c}', "video" => '\u{f03d}',
"video" => '\u{f03d}', "vim" => '\u{e62b}',
"vim" => '\u{e62b}', "xml" => '\u{e619}',
"xml" => '\u{e619}', "yml" => '\u{f481}',
"yml" => '\u{f481}', "yaml" => '\u{f481}',
"yaml" => '\u{f481}', "rar" => '\u{f410}',
"rar" => '\u{f410}', "zip" => '\u{f410}',
"zip" => '\u{f410}', "bz" => '\u{f410}',
"bz" => '\u{f410}', "bz2" => '\u{f410}',
"bz2" => '\u{f410}', "xz" => '\u{f410}',
"xz" => '\u{f410}', "taz" => '\u{f410}',
"taz" => '\u{f410}', "tbz" => '\u{f410}',
"tbz" => '\u{f410}', "tbz2" => '\u{f410}',
"tbz2" => '\u{f410}', "tz" => '\u{f410}',
"tz" => '\u{f410}', "tar" => '\u{f410}',
"tar" => '\u{f410}', "tzo" => '\u{f410}',
"tzo" => '\u{f410}', "lz" => '\u{f410}',
"lz" => '\u{f410}', "lzh" => '\u{f410}',
"lzh" => '\u{f410}', "lzma" => '\u{f410}',
"lzma" => '\u{f410}', "lzo" => '\u{f410}',
"lzo" => '\u{f410}', "gz" => '\u{f410}',
"gz" => '\u{f410}', "deb" => '\u{e77d}',
"deb" => '\u{e77d}', "rpm" => '\u{e7bb}',
"rpm" => '\u{e7bb}', "exe" => '\u{e70f}',
"exe" => '\u{e70f}', "msi" => '\u{e70f}',
"msi" => '\u{e70f}', "dll" => '\u{e70f}',
"dll" => '\u{e70f}', "cab" => '\u{e70f}',
"cab" => '\u{e70f}', "bat" => '\u{e70f}',
"bat" => '\u{e70f}', "cmd" => '\u{e70f}',
"cmd" => '\u{e70f}', "sh" => '\u{e795}',
"sh" => '\u{e795}', "bash" => '\u{e795}',
"bash" => '\u{e795}', "zsh" => '\u{e795}',
"zsh" => '\u{e795}', "fish" => '\u{e795}',
"fish" => '\u{e795}', "csh" => '\u{e795}',
"csh" => '\u{e795}', "ini" => '\u{e615}',
"ini" => '\u{e615}', "toml" => '\u{e615}',
"toml" => '\u{e615}', "cfg" => '\u{e615}',
"cfg" => '\u{e615}', "conf" => '\u{e615}',
"conf" => '\u{e615}', "apk" => '\u{e70e}',
"apk" => '\u{e70e}', "ttf" => '\u{f031}',
"ttf" => '\u{f031}', "woff" => '\u{f031}',
"woff" => '\u{f031}', "woff2" => '\u{f031}',
"woff2" => '\u{f031}', "otf" => '\u{f031}',
"otf" => '\u{f031}', "csv" => '\u{f1c3}',
"csv" => '\u{f1c3}', "tsv" => '\u{f1c3}',
"tsv" => '\u{f1c3}', "xls" => '\u{f1c3}',
"xls" => '\u{f1c3}', "xlsx" => '\u{f1c3}',
"xlsx" => '\u{f1c3}', "ods" => '\u{f1c3}',
"ods" => '\u{f1c3}', "so" => '\u{f17c}',
"so" => '\u{f17c}', "sql" => '\u{f1c0}',
"sql" => '\u{f1c0}', "jar" => '\u{e256}',
"jar" => '\u{e256}', "jad" => '\u{e256}',
"jad" => '\u{e256}', "class" => '\u{e256}',
"class" => '\u{e256}', "war" => '\u{e256}',
"war" => '\u{e256}', "groovy" => '\u{e775}',
"groovy" => '\u{e775}', "iso" => '\u{e271}',
"iso" => '\u{e271}', "lock" => '\u{f023}',
"lock" => '\u{f023}', _ => '\u{f15b}'
_ => '\u{f15b}'
}
} else {
'\u{f15b}'
} }
} else {
'\u{f15b}'
} }
} }

View File

@ -6,8 +6,6 @@ use std::sync::{Mutex, MutexGuard};
use datetime::TimeZone; use datetime::TimeZone;
use zoneinfo_compiled::{CompiledData, Result as TZResult}; use zoneinfo_compiled::{CompiledData, Result as TZResult};
use locale;
use log::debug; use log::debug;
use users::UsersCache; use users::UsersCache;

View File

@ -4,7 +4,6 @@ use std::time::Duration;
use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece}; use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece};
use datetime::fmt::DateFormat; use datetime::fmt::DateFormat;
use locale;
use std::cmp; use std::cmp;