Skip to content

Commit

Permalink
Merge pull request #14 from bootjp/develop
Browse files Browse the repository at this point in the history
release v0.1.2
  • Loading branch information
bootjp committed May 25, 2021
2 parents eefa428 + 272be91 commit c0a1794
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
version = "0.1.2"
name = "bcat"
version = "0.1.1"
authors = ["bootjp / Yoshiaki Ueda <contact@bootjp.me>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
34 changes: 19 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use chrono::{Local, TimeZone};
use filesize::PathExt;
use humansize::{file_size_opts as options, FileSize};
use prettytable::format;
use prettytable::{Cell, Row, Table};
use prettytable::Table;
use std::process;
use std::{fs, os::unix::prelude::CommandExt};
use std::{io::Read, os::linux::fs::MetadataExt};
Expand Down Expand Up @@ -61,24 +61,28 @@ fn list_dir(path: &str) -> Result<()> {
let path = entry?.path();
let meta = fs::metadata(&path)?;
let uid = meta.st_uid();
let user = get_user_by_uid(uid)
.map(|u| u.name().to_str().unwrap_or_default().to_owned())
.unwrap_or_default();
let gid = meta.st_gid();
let group = get_group_by_gid(gid)
.map(|g| g.name().to_str().unwrap_or_default().to_owned())
.unwrap_or_default();
let stat = meta.st_mode();
let size = &path.size_on_disk()?.file_size(options::CONVENTIONAL);
let size = path
.size_on_disk()?
.file_size(options::CONVENTIONAL)
.unwrap_or_default();
let lmtime = Local.timestamp(meta.st_mtime(), 0);

let size = match size {
Ok(s) => s,
Err(_) => continue,
};

table.add_row(Row::new(vec![
Cell::new(&unix_mode::to_string(stat)),
Cell::new(get_user_by_uid(uid).unwrap().name().to_str().unwrap()),
Cell::new(get_group_by_gid(gid).unwrap().name().to_str().unwrap()),
Cell::new(&path.display().to_string()),
Cell::new(&lmtime.to_string()),
Cell::new(size),
]));
table.add_row(row![
&unix_mode::to_string(stat),
&user,
&group,
&path.display().to_string(),
&lmtime.to_string(),
&size,
]);
}
table.printstd();
Ok(())
Expand Down

0 comments on commit c0a1794

Please sign in to comment.