From 3c13d2fd983580e1d5988ae3bad41cb08195894c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 1 Oct 2018 20:10:39 +0300 Subject: Change: use users crate, instead of passwd, for group names --- Cargo.lock | 19 +++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9deae2d..984c9e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,4 +1,23 @@ +[[package]] +name = "libc" +version = "0.2.43" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "summainrs" version = "0.1.0" +dependencies = [ + "users 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "users" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", +] +[metadata] +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum users 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "caa2760fcc10a6ae2c2a35d41c5d69827e4663f0d3889ecfb4d60b343f4139df" diff --git a/Cargo.toml b/Cargo.toml index 924309c..5acabab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" authors = ["Lars Wirzenius "] [dependencies] +users = "0.7" diff --git a/src/main.rs b/src/main.rs index cdaa8e0..6409dd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ use std::fs; use std::os::unix::fs::PermissionsExt; use std::os::linux::fs::MetadataExt; +extern crate users; + mod fswalk; use fswalk::DirTree; @@ -80,10 +82,18 @@ fn format_gid(meta: &fs::Metadata) -> String { fn format_username(meta: &fs::Metadata) -> String { - format!("xxx") + if let Some(u) = users::get_user_by_uid(meta.st_uid()) { + format!("{}", u.name()) + } else { + format!("unknown user") + } } fn format_group(meta: &fs::Metadata) -> String { - format!("xxx") + if let Some(g) = users::get_group_by_gid(meta.st_gid()) { + format!("{}", g.name()) + } else { + format!("unknown group") + } } -- cgit v1.2.1