Skip to content

Commit

Permalink
fix: 🚨 fix clippy lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Feb 11, 2024
1 parent 71f1dba commit bafccaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
run: |
sudo apt update && sudo apt upgrade -y && \
sudo apt install -y protobuf-compiler libprotobuf-dev
- name: Build
run: cargo build --verbose
- name: Run clippy lint
run: cargo clippy --all-targets --all-features
- name: Run tests
run: cargo test --verbose
- name: Build Debian package
Expand Down
24 changes: 8 additions & 16 deletions src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,25 @@ use std::sync::OnceLock;

use uzers::{get_group_by_name, get_user_by_name};

const BUILDER_UID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
const BUILDER_GID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
const RUNNER_UID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
const RUNNER_GID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
static BUILDER_UID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
static BUILDER_GID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
static RUNNER_UID_LOCK: OnceLock<Option<u32>> = OnceLock::new();
static RUNNER_GID_LOCK: OnceLock<Option<u32>> = OnceLock::new();

pub fn builder_uid() -> Option<u32> {
BUILDER_UID_LOCK
.get_or_init(|| get_user_by_name("rsjudge-builder").map(|u| u.uid()))
.clone()
*BUILDER_UID_LOCK.get_or_init(|| get_user_by_name("rsjudge-builder").map(|u| u.uid()))
}

pub fn builder_gid() -> Option<u32> {
BUILDER_GID_LOCK
.get_or_init(|| get_group_by_name("rsjudge-builder").map(|g| g.gid()))
.clone()
*BUILDER_GID_LOCK.get_or_init(|| get_group_by_name("rsjudge-builder").map(|g| g.gid()))
}

pub fn runner_uid() -> Option<u32> {
RUNNER_UID_LOCK
.get_or_init(|| get_user_by_name("rsjudge-runner").map(|u| u.uid()))
.clone()
*RUNNER_UID_LOCK.get_or_init(|| get_user_by_name("rsjudge-runner").map(|u| u.uid()))
}

pub fn runner_gid() -> Option<u32> {
RUNNER_GID_LOCK
.get_or_init(|| get_group_by_name("rsjudge-runner").map(|g| g.gid()))
.clone()
*RUNNER_GID_LOCK.get_or_init(|| get_group_by_name("rsjudge-runner").map(|g| g.gid()))
}

#[cfg(all(test, unix))]
Expand Down

0 comments on commit bafccaf

Please sign in to comment.