Skip to content

Commit

Permalink
Remove happy path in GetPartition
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Feb 12, 2024
1 parent 6620f7f commit 975ccd6
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions core/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,11 @@ func (target *Disk) NewPartition(name string, fsType PartitionFs, start, end int

// GetPartition attempts to locate a partition by its number. For instance, partition 3
// will normally point to `/dev/sda3`, but this might not be the case if partitions have
// been deleted (see [Issue #44]). This function first checks if the desired partition is
// in the correct place, else it searches all partitions in target for the correct one.
// been deleted (see [Issue #44]). This function searches all partitions in target for
// the correct one.
//
// [Issue #44]: https://github.com/Vanilla-OS/Albius/issues/44
func (target *Disk) GetPartition(partNum int) *Partition {
// Happy path: No partitions are missing
if target.Partitions[partNum-1].Number == partNum {
return &target.Partitions[partNum-1]
}

// Missing partition numbers, find correct partition manually
for _, part := range target.Partitions {
if part.Number == partNum {
return &part
Expand Down

0 comments on commit 975ccd6

Please sign in to comment.