Skip to content

Commit ed88d5b

Browse files
committed
Minor fix to how Users are constructed
Signed-off-by: Max Dymond <max.dymond@metaswitch.com>
1 parent 9c7cd94 commit ed88d5b

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/environment.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ pub struct User {
1313
pub gid: nix::unistd::Gid,
1414
}
1515

16+
impl User {
17+
/// Get the user and group ids of the current user
18+
fn current() -> Self {
19+
let uid = nix::unistd::getuid();
20+
let gid = nix::unistd::getgid();
21+
debug!("Current user has uid {} and group {}", uid, gid);
22+
Self { uid, gid }
23+
}
24+
}
25+
1626
#[derive(Debug)]
1727
pub struct Environment {
1828
/// User uid and gid
@@ -35,7 +45,7 @@ impl Environment {
3545
/// Gather information on the environment floki is running in
3646
pub fn gather(config_file: &Option<path::PathBuf>) -> Result<Self, Error> {
3747
let (floki_root, config_path) = resolve_floki_root_and_config(config_file)?;
38-
let user = get_user_details();
48+
let user = User::current();
3949
Ok(Environment {
4050
user_details: user,
4151
current_directory: get_current_working_directory()?,
@@ -47,14 +57,6 @@ impl Environment {
4757
}
4858
}
4959

50-
/// Get the user and group ids of the current user
51-
fn get_user_details() -> User {
52-
let uid = nix::unistd::getuid();
53-
let gid = nix::unistd::getgid();
54-
debug!("Current user has uid {} and group {}", uid, gid);
55-
User { uid, gid }
56-
}
57-
5860
/// Get the current working directory as a String
5961
fn get_current_working_directory() -> Result<path::PathBuf, Error> {
6062
Ok(env::current_dir()?)

0 commit comments

Comments
 (0)