Skip to content

Commit

Permalink
Changed INodeCount to Links
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlakazam committed Jan 17, 2021
1 parent 39dc9e4 commit fd8eeb0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add case-insensitive matching of known filenames and extensions from [poita66](https://github.com/poita66)
- Add Macports installation instructions from [ylluminarious](https://github.com/ylluminarious)
- Implement `--tree -d`, analogous to `tree -d` from [0jdxt](https://github.com/0jdxt) and [Utah Rust](https://github.com/utah-rust)
- Add support for displaying number of hard links from [thealakzam](https://github.com/thealakazam) [#407](https://github.com/Peltoche/lsd/issues/407)

### Changed
- Use last sort flag for sort field from [meain](https://github.com/meain)
Expand Down
8 changes: 4 additions & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum Elem {
valid: bool,
},

INodeCount {
Links {
valid: bool,
},
}
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Colors {
true => Some("so"),
false => Some("no"),
},
Elem::INodeCount { valid } => match valid {
Elem::Links { valid } => match valid {
true => Some("so"),
false => Some("no"),
},
Expand Down Expand Up @@ -251,8 +251,8 @@ impl Colors {
// INode
m.insert(Elem::INode { valid: true }, Colour::Fixed(13)); // Pink
m.insert(Elem::INode { valid: false }, Colour::Fixed(245)); // Grey
m.insert(Elem::INodeCount { valid: true }, Colour::Fixed(134));
m.insert(Elem::INodeCount { valid: false }, Colour::Fixed(222));
m.insert(Elem::Links { valid: true }, Colour::Fixed(134));
m.insert(Elem::Links { valid: false }, Colour::Fixed(222));

m
}
Expand Down
2 changes: 1 addition & 1 deletion src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ fn get_output<'a>(
for block in flags.blocks.0.iter() {
match block {
Block::INode => strings.push(meta.inode.render(colors)),
Block::INodeCount => strings.push(meta.inode_count.render(colors)),
Block::Links => strings.push(meta.links.render(colors)),
Block::Permission => {
let s: &[ColoredString] = &[
meta.file_type.render(colors),
Expand Down
10 changes: 5 additions & 5 deletions src/flags/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl Blocks {
Block::Size,
Block::Date,
Block::Name,
Block::INodeCount,
Block::Links,
])
}

Expand Down Expand Up @@ -165,7 +165,7 @@ pub enum Block {
Date,
Name,
INode,
INodeCount,
Links,
}

impl TryFrom<&str> for Block {
Expand All @@ -181,7 +181,7 @@ impl TryFrom<&str> for Block {
"date" => Ok(Self::Date),
"name" => Ok(Self::Name),
"inode" => Ok(Self::INode),
"links" => Ok(Self::INodeCount),
"links" => Ok(Self::Links),
_ => Err(format!("Not a valid block name: {}", &string)),
}
}
Expand Down Expand Up @@ -504,7 +504,7 @@ mod test_block {
}

#[test]
fn test_inode_count() {
assert_eq!(Ok(Block::INodeCount), Block::try_from("links"));
fn test_links() {
assert_eq!(Ok(Block::Links), Block::try_from("links"));
}
}
18 changes: 9 additions & 9 deletions src/meta/inode_count.rs → src/meta/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::color::{ColoredString, Colors, Elem};
use std::fs::Metadata;

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct INodeCount {
pub struct Links {
nlink: Option<u64>,
}

impl<'a> From<&'a Metadata> for INodeCount {
impl<'a> From<&'a Metadata> for Links {
#[cfg(unix)]
fn from(meta: &Metadata) -> Self {
use std::os::unix::fs::MetadataExt;
Expand All @@ -22,19 +22,19 @@ impl<'a> From<&'a Metadata> for INodeCount {
}
}

impl INodeCount {
impl Links {
pub fn render(&self, colors: &Colors) -> ColoredString {
match self.nlink {
Some(i) => colors.colorize(i.to_string(), &Elem::INodeCount { valid: true }),
None => colors.colorize(String::from("-"), &Elem::INodeCount { valid: false }),
Some(i) => colors.colorize(i.to_string(), &Elem::Links { valid: true }),
None => colors.colorize(String::from("-"), &Elem::Links { valid: false }),
}
}
}

#[cfg(test)]
#[cfg(unix)]
mod tests {
use super::INodeCount;
use super::Links;
use std::env;
use std::io;
use std::path::Path;
Expand All @@ -52,11 +52,11 @@ mod tests {
let success = cross_platform_touch(&file_path).unwrap().success();
assert!(success, "failed to exec touch");

let inode = INodeCount::from(&file_path.metadata().unwrap());
let links = Links::from(&file_path.metadata().unwrap());

#[cfg(unix)]
assert!(inode.nlink.is_some());
assert!(links.nlink.is_some());
#[cfg(windows)]
assert!(inode.nlink.is_none());
assert!(links.nlink.is_none());
}
}
10 changes: 5 additions & 5 deletions src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod date;
mod filetype;
mod indicator;
mod inode;
mod inode_count;
mod links;
pub mod name;
mod owner;
mod permissions;
Expand All @@ -16,7 +16,7 @@ pub use self::date::Date;
pub use self::filetype::FileType;
pub use self::indicator::Indicator;
pub use self::inode::INode;
pub use self::inode_count::INodeCount;
pub use self::links::Links;
pub use self::name::Name;
pub use self::owner::Owner;
pub use self::permissions::Permissions;
Expand All @@ -43,7 +43,7 @@ pub struct Meta {
pub symlink: SymLink,
pub indicator: Indicator,
pub inode: INode,
pub inode_count: INodeCount,
pub links: Links,
pub content: Option<Vec<Meta>>,
}

Expand Down Expand Up @@ -222,11 +222,11 @@ impl Meta {
let file_type = FileType::new(&metadata, symlink_meta.as_ref(), &permissions);
let name = Name::new(&path, file_type);
let inode = INode::from(&metadata);
let inode_count = INodeCount::from(&metadata);
let links = Links::from(&metadata);

Ok(Self {
inode,
inode_count,
links,
path: path.to_path_buf(),
symlink: SymLink::from(path),
size: Size::from(&metadata),
Expand Down

0 comments on commit fd8eeb0

Please sign in to comment.