about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-21 18:21:49 +0000
committerGitHub <noreply@github.com>2020-12-21 18:21:49 +0000
commite4f922a74d66153ac099ad909e0ea5151292b8a5 (patch)
treea1a91f10170e2f5ad5372ac96b63aa3fcff4e91e
parent87762874ef53b7a24c13e78faded7bc88ea7e435 (diff)
parentee734668308df4549eb2ddbd7fed7911dc3a7ba3 (diff)
downloadrust-e4f922a74d66153ac099ad909e0ea5151292b8a5.tar.gz
rust-e4f922a74d66153ac099ad909e0ea5151292b8a5.zip
Merge #6985
6985: Use /etc/os-release to check for NixOS r=matklad a=lnicola

Closes #5641

The motivation in #5641 isn't too strong, but /etc/os-release exists on pretty much every Linux distro, while /etc/nixos sounds like an implementation detail.


Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
-rw-r--r--editors/code/src/main.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 191960960a3..4eaaed62bdc 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -340,7 +340,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     });
 
     // Patching executable if that's NixOS.
-    if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
+    if (await isNixOs()) {
         await patchelf(dest);
     }
 
@@ -348,6 +348,15 @@ async function getServer(config: Config, state: PersistentState): Promise<string
     return dest;
 }
 
+async function isNixOs(): Promise<boolean> {
+    try {
+        const contents = await fs.readFile("/etc/os-release");
+        return contents.indexOf("ID=nixos") !== -1;
+    } catch (e) {
+        return false;
+    }
+}
+
 async function downloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
     while (true) {
         try {