diff options
| author | Maarten Vanraes <alien@mageia.org> | 2016-08-06 14:21:24 +0200 | 
|---|---|---|
| committer | Maarten Vanraes <alien@mageia.org> | 2016-08-06 14:21:24 +0200 | 
| commit | b30d967dc49238fcb1e20156bc3d2f53111e17c8 (patch) | |
| tree | 93cd0ec12245e89955fe22474224e94e154c95e7 /lib/ManaTools/Shared | |
| parent | 4ee9e61cc2c698897af40d56df5344b8797f31c3 (diff) | |
| download | manatools-b30d967dc49238fcb1e20156bc3d2f53111e17c8.tar manatools-b30d967dc49238fcb1e20156bc3d2f53111e17c8.tar.gz manatools-b30d967dc49238fcb1e20156bc3d2f53111e17c8.tar.bz2 manatools-b30d967dc49238fcb1e20156bc3d2f53111e17c8.tar.xz manatools-b30d967dc49238fcb1e20156bc3d2f53111e17c8.zip | |
Part: add a closest helper function
Diffstat (limited to 'lib/ManaTools/Shared')
| -rw-r--r-- | lib/ManaTools/Shared/disk_backend/Part.pm | 29 | 
1 files changed, 29 insertions, 0 deletions
| diff --git a/lib/ManaTools/Shared/disk_backend/Part.pm b/lib/ManaTools/Shared/disk_backend/Part.pm index 39502ec0..44961628 100644 --- a/lib/ManaTools/Shared/disk_backend/Part.pm +++ b/lib/ManaTools/Shared/disk_backend/Part.pm @@ -364,6 +364,35 @@ sub find_parts {      return @res;  } +sub find_closest { +    my $self = shift; +    my $partstate = shift; +    my $identify = shift; +    my $parttype = shift; +    my $parameters = shift; +    my @tags = @_; +    my @res = ($self); +    while (scalar(@res) > 0) { +        my @next = (); +        for my $p (@res) { +            my $links = $p->links(); +            for my $link (@{$links}) { +                if ($link->check($p, $parttype, @tags)) { +                    if (!defined $identify || $identify->($link->part(), $parameters)) { +                        # if it's the state we're looking for, just return it +                        return $link->part() if ($link->part()->is_state($partstate)); +                    } + +                    # add it to the next list to be checked +                    push @next, $link->part(); +                } +            } +        } +        @res = @next; +    } +    return undef; +} +  sub find_part {      my $self = shift;      my $parttype = shift; | 
