From c7b9f61bd2b31345bb320be5874de1c181d74eb5 Mon Sep 17 00:00:00 2001 From: ziyouwa Date: Mon, 25 Mar 2024 15:36:18 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E4=BB=8Elinux?= =?UTF-8?q?=E6=88=96wsl=E7=B3=BB=E7=BB=9F=E8=8E=B7=E5=8F=96id=202=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0.gitignore=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ common/src/identifier.rs | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..faceae6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +target/* +vnt/src/proto/message.rs +vnt-cli/src/generated_serial_number.rs +Cargo.lock \ No newline at end of file diff --git a/common/src/identifier.rs b/common/src/identifier.rs index 94c3520..5a12ae5 100644 --- a/common/src/identifier.rs +++ b/common/src/identifier.rs @@ -51,6 +51,13 @@ pub fn get_unique_identifier() -> Option { #[cfg(target_os = "linux")] pub fn get_unique_identifier() -> Option { use std::process::Command; + + // 对 linux 或 wsl 来说,读取 /etc/machine-id 即可获取当前操作系统的 + // 唯一标识,而且某些环境没有预装`dmidecode`命令 + if let Ok(identifier) = std::fs::read_to_string("/etc/machine-id") { + return Some(identifier); + } + let output = match Command::new("dmidecode") .arg("-s") .arg("system-uuid")