diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ManaTools/Shared/disk_backend/BlockDevice.pm | 23 | ||||
| -rw-r--r-- | lib/ManaTools/Shared/disk_backend/Mountable.pm | 23 | ||||
| -rw-r--r-- | lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm | 19 | 
3 files changed, 65 insertions, 0 deletions
| diff --git a/lib/ManaTools/Shared/disk_backend/BlockDevice.pm b/lib/ManaTools/Shared/disk_backend/BlockDevice.pm index f20c0fda..9acce67e 100644 --- a/lib/ManaTools/Shared/disk_backend/BlockDevice.pm +++ b/lib/ManaTools/Shared/disk_backend/BlockDevice.pm @@ -190,4 +190,27 @@ sub sync_majorminor {      }  } +#============================================================= + +=head2 find_path + +=head3 DESCRIPTION + +    this method finds in descendants the Mount part and gets the path from it + +=cut + +#============================================================= +sub find_path { +    my $self = shift; +    my $partstate = shift; +    # finding a path only works if one has a Mount or Mountable child, +    my @children = $self->children($partstate); +    for my $child (@children) { +        return $child->path() if ($child->isa('ManaTools::Shared::disk_backend::Part::Mount')); +        return $child->find_path($partstate) if ($child->does('ManaTools::Shared::disk_backend::Mountable')); +    } +    return undef; +} +  1; diff --git a/lib/ManaTools/Shared/disk_backend/Mountable.pm b/lib/ManaTools/Shared/disk_backend/Mountable.pm index abe8404d..33cb1463 100644 --- a/lib/ManaTools/Shared/disk_backend/Mountable.pm +++ b/lib/ManaTools/Shared/disk_backend/Mountable.pm @@ -61,4 +61,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  use Moose::Role; +#============================================================= + +=head2 find_path + +=head3 DESCRIPTION + +    this method finds in descendants the Mount part and gets the path from it + +=cut + +#============================================================= +sub find_path { +    my $self = shift; +    my $partstate = shift; +    # finding a path only works if one has a Mount or Mountable child, +    my @children = $self->children($partstate); +    for my $child (@children) { +        return $child->path() if ($child->isa('ManaTools::Shared::disk_backend::Part::Mount')); +        return $child->find_path($partstate) if ($child->does('ManaTools::Shared::disk_backend::Mountable')); +    } +    return undef; +} +  1; diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm index 4c7cb707..508a298d 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm @@ -288,5 +288,24 @@ class_has '+restrictions' => (      }  ); +around('find_path', sub { +    my $orig = shift; +    my $self = shift; +    my $partstate = shift; + +    # first try the standard method +    my $path = $self->$orig($partstate); +    return $path if (defined $path); + +    # subvolumes can check parent subvolumes and add the relative path +    my @parents = $self->find_parts($partstate, 'parent'); +    for my $parent (@parents) { +        if ($parent->isa('ManaTools::Shared::disk_backend::Part::BtrfsVol')) { +            $path = $parent->find_path($partstate); +            return $path . substr($self->prop('label'), length($parent->prop('label'))) if defined($path); +        } +    } +    return undef; +});  1; | 
