From 3394beab67b9ce17b240e18a3af725c87f793a89 Mon Sep 17 00:00:00 2001 From: jasonwitty Date: Tue, 26 Aug 2025 00:18:10 -0700 Subject: [PATCH] chore: make pre-commit resilient when cargo absent --- .githooks/pre-commit | 15 +++++++++++++-- socktop_agent/src/metrics.rs | 8 ++++---- 2 files changed, 17 insertions(+), 6 deletions(-) mode change 100644 => 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit old mode 100644 new mode 100755 index e4caf43..7f1763e --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,11 +1,22 @@ #!/usr/bin/env bash +# This repository uses a custom hooks directory (.githooks). To enable this pre-commit hook run: +# git config core.hooksPath .githooks +# Ensure this file is executable: chmod +x .githooks/pre-commit set -euo pipefail echo "[pre-commit] Running cargo fmt --all" >&2 if ! command -v cargo >/dev/null 2>&1; then - echo "[pre-commit] cargo not found in PATH" >&2 - exit 1 + # Try loading rustup environment (common install path) + if [ -f "$HOME/.cargo/env" ]; then + # shellcheck source=/dev/null + . "$HOME/.cargo/env" + fi +fi + +if ! command -v cargo >/dev/null 2>&1; then + echo "[pre-commit] cargo not found in PATH; skipping fmt (install Rust or adjust PATH)." >&2 + exit 0 fi cargo fmt --all diff --git a/socktop_agent/src/metrics.rs b/socktop_agent/src/metrics.rs index 0770f51..a5d4ee6 100644 --- a/socktop_agent/src/metrics.rs +++ b/socktop_agent/src/metrics.rs @@ -476,8 +476,8 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload { } }) .collect(); - // Automatic scaling (enabled by default): if sum of per-process CPU exceeds global - // CPU by >5%, scale all process CPU values proportionally so the sum matches global. + // Automatic scaling (enabled by default): if sum of per-process CPU exceeds global + // CPU by >5%, scale all process CPU values proportionally so the sum matches global. if std::env::var("SOCKTOP_AGENT_SCALE_PROC_CPU") .map(|v| v != "0") .unwrap_or(true) @@ -486,8 +486,8 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload { let global = sys.global_cpu_usage(); if sum > 0.0 && global > 0.0 { let scale = global / sum; - if scale < 0.95 { - // only scale if we're at least 5% over + if scale < 0.95 { + // only scale if we're at least 5% over for p in &mut list { p.cpu_usage = (p.cpu_usage * scale).clamp(0.0, 100.0); }