Fixed: snap root disk and changed to compiler flags instead of env variables for detection

This commit is contained in:
aristocratos 2021-10-06 11:25:10 +02:00
parent ad0b3d6b09
commit dbcd12b9d0
2 changed files with 16 additions and 8 deletions

View File

@ -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

View File

@ -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"};