From 97c268200eacef5bf70a7897b4508ad610fed046 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Sun, 6 Jun 2021 17:28:15 +0000 Subject: [PATCH] Added InUse flag to Device, fixed logic bugs --- internal/storage/storage.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 1bdc650..e48e1e5 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -13,6 +13,7 @@ type Device struct { ID string `json:"id"` Name string `json:"name"` Size string `json:"size"` + InUse bool `json:"in_use"` MainDevice bool `json:"main_device"` MAJ string `json:"maj"` MIN string `json:"min"` @@ -74,6 +75,7 @@ func GetDevices() []Device { var currentPartitions []Partition firstDevice := true + currentDeviceInUseFlag := false for scanner.Scan() { // 1 Device is represented here. Extract words in order for filling a Device struct @@ -95,6 +97,8 @@ func GetDevices() []Device { if !firstDevice { fmt.Println("Appending finalized device info to list") currentDevice.Partitions = currentPartitions + currentDevice.InUse = currentDeviceInUseFlag + currentDeviceInUseFlag = false currentPartitions = []Partition{} devices = append(devices, currentDevice) } else { @@ -127,8 +131,9 @@ func GetDevices() []Device { fmt.Println("Processing Partition") mountpoint := "" - if len(deviceRawInfo) > 7 { - mountpoint = deviceRawInfo[7] + if len(deviceRawInfo) >= 7 { + mountpoint = deviceRawInfo[6] + currentDeviceInUseFlag = true } // It is a partition, part of the last device read. @@ -149,6 +154,8 @@ func GetDevices() []Device { } + currentDevice.Partitions = currentPartitions + currentDevice.InUse = currentDeviceInUseFlag devices = append([]Device{currentDevice}, devices...) // Prepending the first device... return devices