Use curlies consistently

This commit is contained in:
Ben S 2014-11-25 20:50:23 +00:00
parent e1d3512a69
commit 6ade060eb6
4 changed files with 29 additions and 29 deletions

View File

@ -37,7 +37,7 @@ impl<'a> File<'a> {
// encounters a link that's target is non-existent.
fs::lstat(&path).map(|stat| File::with_stat(stat, path.clone(), parent))
}
pub fn with_stat(stat: io::FileStat, path: Path, parent: Option<&'a Dir<'a>>) -> File<'a> {
let v = path.filename().unwrap(); // fails if / or . or ..
let filename = String::from_utf8(v.to_vec()).unwrap_or_else(|_| panic!("Name was not valid UTF-8"));
@ -79,7 +79,7 @@ impl<'a> File<'a> {
if self.ext.is_none() {
return vec![];
}
let ext = self.ext.clone().unwrap();
match ext.as_slice() {
"class" => vec![self.path.with_extension("java")], // Java
@ -107,11 +107,11 @@ impl<'a> File<'a> {
Permissions => {
self.permissions_string()
},
FileName => {
self.file_name()
},
FileSize(use_iec) => {
self.file_size(use_iec)
},
@ -127,7 +127,7 @@ impl<'a> File<'a> {
Inode => {
Purple.paint(self.stat.unstable.inode.to_string().as_slice())
},
Blocks => {
if self.stat.kind == io::TypeFile || self.stat.kind == io::TypeSymlink {
Cyan.paint(self.stat.unstable.blocks.to_string().as_slice())
@ -146,7 +146,7 @@ impl<'a> File<'a> {
let style = if unix.uid == uid { Yellow.bold() } else { Plain };
style.paint(user_name.as_slice())
},
Group => {
let gid = self.stat.unstable.gid as u32;
unix.load_group(gid);
@ -184,7 +184,8 @@ impl<'a> File<'a> {
fn target_file_name_and_arrow(&self, target_path: Path) -> String {
let v = target_path.filename().unwrap();
let filename = String::from_utf8_lossy(v).to_string();
// Use stat instead of lstat - we *want* to follow links.
let link_target = fs::stat(&target_path).map(|stat| File {
path: target_path.clone(),
dir: self.dir,
@ -212,10 +213,12 @@ impl<'a> File<'a> {
// at one of those numbers and gained any information from it.
if self.stat.kind == io::TypeDirectory {
GREY.paint("-")
} else {
}
else {
let (size, suffix) = if use_iec_prefixes {
format_IEC_bytes(self.stat.size)
} else {
}
else {
format_metric_bytes(self.stat.size)
};
@ -237,7 +240,7 @@ impl<'a> File<'a> {
pub fn file_colour(&self) -> Style {
self.get_type().style()
}
fn has_multiple_links(&self) -> bool {
self.stat.kind == io::TypeFile && self.stat.unstable.nlink > 1
}
@ -264,7 +267,8 @@ impl<'a> File<'a> {
fn permission_bit(bits: io::FilePermission, bit: io::FilePermission, character: &'static str, style: Style) -> String {
if bits.contains(bit) {
style.paint(character.as_slice())
} else {
}
else {
GREY.paint("-".as_slice())
}
}

View File

@ -40,7 +40,6 @@ pub struct Options {
pub view: View,
}
impl Options {
pub fn getopts(args: Vec<String>) -> Result<Options, int> {
let opts = [
@ -59,7 +58,7 @@ impl Options {
getopts::optflag("x", "across", "sort multi-column view entries across"),
getopts::optflag("?", "help", "show list of command-line options"),
];
let matches = match getopts::getopts(args.tail(), &opts) {
Ok(m) => m,
Err(e) => {
@ -67,7 +66,7 @@ impl Options {
return Err(1);
}
};
if matches.opt_present("help") {
println!("exa - ls with more features\n\n{}", getopts::usage("Usage:\n exa [options] [files...]", &opts))
return Err(2);
@ -83,7 +82,7 @@ impl Options {
view: Options::view(&matches),
})
}
fn view(matches: &getopts::Matches) -> View {
if matches.opt_present("long") {
View::Details(Options::columns(matches))
@ -98,7 +97,7 @@ impl Options {
}
}
}
fn columns(matches: &getopts::Matches) -> Vec<Column> {
let mut columns = vec![];
@ -111,7 +110,7 @@ impl Options {
if matches.opt_present("links") {
columns.push(HardLinks);
}
columns.push(FileSize(matches.opt_present("binary")));
if matches.opt_present("blocks") {

View File

@ -24,7 +24,8 @@ impl SortPart {
Some(num) => Numeric(num),
None => Stringular(slice.to_string()),
}
} else {
}
else {
SortPart::Stringular(slice.to_ascii_lower())
}
}

View File

@ -104,25 +104,21 @@ impl Unix {
let mut i = 0;
// The list of members is a pointer to a pointer of
// characters, terminated by a null pointer. So the first call
// to `as_ref` will always succeed, as that memory is
// guaranteed to be there (unless we go past the end of RAM).
// The second call will return None if it's a null pointer.
// characters, terminated by a null pointer.
loop {
match unsafe { group.offset(i).as_ref() } {
Some(&username) => {
if username == ptr::null() {
return false;
return false; // username was null, weird
}
else if unsafe { String::from_raw_buf(username as *const u8) } == *uname {
return true;
return true; // group found!
}
else {
i += 1;
i += 1; // try again with the next group
}
},
None => return false,
None => return false, // no more groups to check, and none found
}
}
}
@ -137,9 +133,9 @@ impl Unix {
let group_name = unsafe { Some(String::from_raw_buf(r.gr_name as *const u8)) };
if !self.groups.contains_key(&gid) {
self.groups.insert(gid, Unix::group_membership(r.gr_mem, &self.username));
}
}
self.group_names.insert(gid, group_name);
}
}
}
}
}