From dbcd12b9d0d7c8c5ce95e066b40118a6faa78063 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Wed, 6 Oct 2021 11:25:10 +0200 Subject: [PATCH] Fixed: snap root disk and changed to compiler flags instead of env variables for detection --- snap/snapcraft.yaml | 3 +-- src/linux/btop_collect.cpp | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index f7a87ba..17d75ed 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -29,7 +29,6 @@ apps: environment: LC_ALL: C.UTF-8 LANG: C.UTF-8 - BTOP_SNAPPED: true plugs: - mount-observe - process-control @@ -48,7 +47,7 @@ parts: make-parameters: - PREFIX=/usr/local - STATIC=true - - BTOP_SNAPPED=1 + - ADDFLAGS="-D SNAPPED" build-packages: - coreutils diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 376be7f..ff72654 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -686,7 +686,6 @@ namespace Mem { auto& show_disks = Config::getB("show_disks"); auto totalMem = get_totalMem(); auto& mem = current_mem; - static const bool snapped = (getenv("BTOP_SNAPPED") != NULL); mem.stats.at("swap_total") = 0; @@ -791,8 +790,12 @@ namespace Mem { for (string instr; diskread >> instr;) { if (not instr.starts_with('#')) { diskread >> instr; - if (snapped and instr == "/") fstab.push_back("/mnt"); - else if (not is_in(instr, "none", "swap")) fstab.push_back(instr); + #ifdef SNAPPED + if (instr == "/") fstab.push_back("/mnt"); + else if (not is_in(instr, "none", "swap")) fstab.push_back(instr); + #else + if (not is_in(instr, "none", "swap")) fstab.push_back(instr); + #endif } diskread.ignore(SSmax, '\n'); } @@ -829,7 +832,10 @@ namespace Mem { if (not disks.contains(mountpoint)) { disks[mountpoint] = disk_info{fs::canonical(dev, ec), fs::path(mountpoint).filename()}; if (disks.at(mountpoint).dev.empty()) disks.at(mountpoint).dev = dev; - if (disks.at(mountpoint).name.empty()) disks.at(mountpoint).name = (mountpoint == "/" or (snapped and mountpoint == "/mnt") ? "root" : mountpoint); + #ifdef SNAPPED + if (mountpoint == "/mnt") disks.at(mountpoint).name = "root"; + #endif + if (disks.at(mountpoint).name.empty()) disks.at(mountpoint).name = (mountpoint == "/" ? "root" : mountpoint); string devname = disks.at(mountpoint).dev.filename(); while (devname.size() >= 2) { if (fs::exists("/sys/block/" + devname + "/stat", ec) and access(string("/sys/block/" + devname + "/stat").c_str(), R_OK) == 0) { @@ -875,8 +881,11 @@ namespace Mem { //? Setup disks order in UI and add swap if enabled mem.disks_order.clear(); - if (snapped and disks.contains("/mnt")) mem.disks_order.push_back("/mnt"); - else if (disks.contains("/")) mem.disks_order.push_back("/"); + #ifdef SNAPPED + if (disks.contains("/mnt")) mem.disks_order.push_back("/mnt"); + #else + if (disks.contains("/")) mem.disks_order.push_back("/"); + #endif if (swap_disk and has_swap) { mem.disks_order.push_back("swap"); if (not disks.contains("swap")) disks["swap"] = {"", "swap"};