From 035ae46ee513a1f51105a0e8dbc6bb1741d06e33 Mon Sep 17 00:00:00 2001 From: lbl8603 <49143209+lbl8603@users.noreply.github.com> Date: Thu, 9 May 2024 20:07:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=BB=A4/etc/machine-id=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/identifier.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/src/identifier.rs b/common/src/identifier.rs index 5a12ae5..4d3590b 100644 --- a/common/src/identifier.rs +++ b/common/src/identifier.rs @@ -55,7 +55,10 @@ pub fn get_unique_identifier() -> Option { // 对 linux 或 wsl 来说,读取 /etc/machine-id 即可获取当前操作系统的 // 唯一标识,而且某些环境没有预装`dmidecode`命令 if let Ok(identifier) = std::fs::read_to_string("/etc/machine-id") { - return Some(identifier); + let identifier = identifier.trim(); + if !identifier.is_empty() { + return Some(identifier.to_string()); + } } let output = match Command::new("dmidecode") @@ -70,7 +73,7 @@ pub fn get_unique_identifier() -> Option { }; let result = String::from_utf8_lossy(&output.stdout); - let identifier = result.trim().to_string(); + let identifier = result.trim(); if identifier.is_empty() { None } else {