From cc236c0e50bac002424c5c9bc7ea64a976ac3838 Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Fri, 20 Dec 2024 14:56:32 +0100 Subject: [PATCH] convert block device to partition info method --- .../os/connection/snapshot/blockdevices.go | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/providers/os/connection/snapshot/blockdevices.go b/providers/os/connection/snapshot/blockdevices.go index de57d9d658..81e44f2212 100644 --- a/providers/os/connection/snapshot/blockdevices.go +++ b/providers/os/connection/snapshot/blockdevices.go @@ -9,6 +9,7 @@ import ( "io" "math" "os" + "path" "sort" "strconv" "strings" @@ -32,6 +33,17 @@ type BlockDevice struct { Aliases []string `json:"-"` } +func (b BlockDevice) PartitionInfo(devPath string) *PartitionInfo { + return &PartitionInfo{ + Name: path.Join(devPath, b.Name), + FsType: b.FsType, + Label: b.Label, + Uuid: b.Uuid, + MountPoint: b.MountPoint, + Aliases: b.Aliases, + } +} + type Size int64 func (s *Size) UnmarshalJSON(data []byte) error { @@ -211,13 +223,7 @@ func (device BlockDevice) GetPartitions(includeBoot bool, includeMounted bool) ( partitions = append(partitions, mapLVM2Partitions(partition)...) continue } - devFsName := "/dev/" + partition.Name - partitions = append(partitions, &PartitionInfo{ - Name: devFsName, FsType: partition.FsType, - Label: partition.Label, Uuid: partition.Uuid, - Aliases: partition.Aliases, - MountPoint: partition.MountPoint, - }) + partitions = append(partitions, partition.PartitionInfo("/dev")) } else { log.Debug(). Str("name", partition.Name). @@ -236,11 +242,7 @@ func (device BlockDevice) GetPartitions(includeBoot bool, includeMounted bool) ( func mapLVM2Partitions(part BlockDevice) (partitions []*PartitionInfo) { for _, p := range part.Children { - devFsName := "/dev/mapper/" + p.Name - partitions = append(partitions, &PartitionInfo{ - Name: devFsName, FsType: p.FsType, - Label: p.Label, Uuid: p.Uuid, - }) + partitions = append(partitions, p.PartitionInfo("/dev/mapper")) } return partitions