Skip to content

Commit

Permalink
✨ add aliases to partitions info (#4859)
Browse files Browse the repository at this point in the history
* feat: pass aliases to partitions info

* comments
  • Loading branch information
slntopp authored Nov 14, 2024
1 parent 0d5431c commit 7ad82eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions providers/os/connection/snapshot/blockdevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ func (blockEntries BlockDevices) FindDevice(requested string) (BlockDevice, erro
func (device BlockDevice) GetMountablePartitions(includeAll bool) ([]*PartitionInfo, error) {
log.Debug().Str("device", device.Name).Msg("get partitions for device")

blockDevices := device.Children
blockDevices := &BlockDevices{
BlockDevices: device.Children,
}

// sort the candidates by size, so we can pick the largest one
sortBlockDevicesBySize(blockDevices)
sortBlockDevicesBySize(blockDevices.BlockDevices)
blockDevices.findAliases()

filter := func(partition BlockDevice) bool {
if partition.FsType == "" {
Expand All @@ -184,14 +187,15 @@ func (device BlockDevice) GetMountablePartitions(includeAll bool) ([]*PartitionI
}

partitions := []*PartitionInfo{}
for _, partition := range blockDevices {
for _, partition := range blockDevices.BlockDevices {
log.Debug().Str("name", partition.Name).Int64("size", int64(partition.Size)).Msg("checking partition")
if filter(partition) {
log.Debug().Str("name", partition.Name).Msg("found suitable partition")
devFsName := "/dev/" + partition.Name
partitions = append(partitions, &PartitionInfo{
Name: devFsName, FsType: partition.FsType,
Label: partition.Label, Uuid: partition.Uuid,
Aliases: partition.Aliases,
})
} else {
log.Debug().
Expand Down
6 changes: 5 additions & 1 deletion providers/os/connection/snapshot/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import (
)

type PartitionInfo struct {
Name string
// Device name (e.g. /dev/sda1)
Name string
// Filesystem type (e.g. ext4)
FsType string

// Resolved device name aliases (e.g. /dev/sda1 -> /dev/nvme0n1p1)
Aliases []string
// (optional) Label is the partition label
Label string
// (optional) UUID is the partition UUID
Expand Down

0 comments on commit 7ad82eb

Please sign in to comment.