summaryrefslogtreecommitdiff
path: root/src/user_info.rs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-08-11 22:04:19 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-08-15 21:40:35 +0200
commit64da82c661b2a28c7a258bd30c0084633d0e1896 (patch)
treee631e496b70f10d8414a3d1962797aa6354de918 /src/user_info.rs
parent2203a06532979e8c4772dcb134c109e1f308031a (diff)
Create group directories if they don't already exist
- With the correct ownership - With the correct permissions Fix #5
Diffstat (limited to 'src/user_info.rs')
-rw-r--r--src/user_info.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/user_info.rs b/src/user_info.rs
index 7a42db9..a352adb 100644
--- a/src/user_info.rs
+++ b/src/user_info.rs
@@ -1,4 +1,4 @@
-use nix::unistd::{getgroups, getuid, Group, User};
+use nix::unistd::{getgroups, getuid, Gid, Group, User};
pub fn get_username() -> Option<String> {
let uid = getuid();
@@ -13,6 +13,13 @@ pub fn get_user_groups() -> Vec<String> {
.collect()
}
+pub fn get_gid(group_name: &str) -> Option<Gid> {
+ nix::unistd::Group::from_name(&group_name)
+ .ok()
+ .flatten()
+ .map(|group| group.gid)
+}
+
#[cfg(test)]
mod test {
use super::*;