aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-08-06 13:59:38 +0200
committerMaarten Vanraes <alien@mageia.org>2016-08-06 13:59:38 +0200
commit4ee9e61cc2c698897af40d56df5344b8797f31c3 (patch)
tree356778d604c4503cee0329b729557e9ec9eb3301
parent47c08e9dbae7dba4fc23da097a82dee2b3503348 (diff)
downloadmanatools-4ee9e61cc2c698897af40d56df5344b8797f31c3.tar
manatools-4ee9e61cc2c698897af40d56df5344b8797f31c3.tar.gz
manatools-4ee9e61cc2c698897af40d56df5344b8797f31c3.tar.bz2
manatools-4ee9e61cc2c698897af40d56df5344b8797f31c3.tar.xz
manatools-4ee9e61cc2c698897af40d56df5344b8797f31c3.zip
Mountable: allow to find the mount path
-rw-r--r--lib/ManaTools/Shared/disk_backend/BlockDevice.pm23
-rw-r--r--lib/ManaTools/Shared/disk_backend/Mountable.pm23
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm19
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;