From 53640eaac2683ba9f974bcbd8ef6ae04dc52e775 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Tue, 6 Feb 2024 13:24:20 -0700 Subject: [PATCH] fix arm64 build --- ext/node/ops/os/cpus.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ext/node/ops/os/cpus.rs b/ext/node/ops/os/cpus.rs index 6c852dce7c7643..bf83f7e7d5b6cb 100644 --- a/ext/node/ops/os/cpus.rs +++ b/ext/node/ops/os/cpus.rs @@ -245,11 +245,13 @@ pub fn cpu_info() -> Option> { let fp = std::fs::File::open("/proc/stat").ok()?; let reader = std::io::BufReader::new(fp); + let mut count = 0; for (i, line) in reader.lines().enumerate() { let line = line.ok()?; if !line.starts_with("cpu") { break; } + count = i; let mut fields = line.split_whitespace(); fields.next()?; let user = fields.next()?.parse::().ok()?; @@ -268,7 +270,7 @@ pub fn cpu_info() -> Option> { let fp = std::fs::File::open("/proc/cpuinfo").ok()?; let reader = std::io::BufReader::new(fp); - let mut i = 0; + let mut j = 0; for line in reader.lines() { let line = line.ok()?; if !line.starts_with("model name") { @@ -278,11 +280,16 @@ pub fn cpu_info() -> Option> { fields.next()?; let model = fields.next()?.trim(); - cpus[i].model = model.to_string(); - i += 1; + cpus[j].model = model.to_string(); + j += 1; } - cpus.truncate(i); + while j < count { + cpus[j].model = "unknown".to_string(); + j += 1; + } + + cpus.truncate(count); Some(cpus) }