From be11afaf5b9090620030f681dc9bb38298c49895 Mon Sep 17 00:00:00 2001 From: Maarten Vanraes Date: Sun, 24 Jul 2016 08:38:22 +0200 Subject: handle fstypes differently --- lib/ManaTools/Shared/disk_backend.pm | 24 +++++++++++++++++++++++ lib/ManaTools/Shared/disk_backend/FileSystem.pm | 8 +++++--- lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm | 6 +++++- lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm | 8 +++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/ManaTools/Shared/disk_backend.pm b/lib/ManaTools/Shared/disk_backend.pm index f5bca59c..199f76af 100644 --- a/lib/ManaTools/Shared/disk_backend.pm +++ b/lib/ManaTools/Shared/disk_backend.pm @@ -129,12 +129,24 @@ has 'plugins' => ( isa => 'ArrayRef[ManaTools::Shared::disk_backend::Plugin]', default => sub { my $self = shift; + my $fs = $self->fs(); my $plugins = []; my @more = (); for my $pluginfile (glob((module_path($self->blessed()) =~ s/\.pm$//r ) ."/Plugin/*.pm")) { my $pluginclass = "ManaTools::Shared::disk_backend::Plugin::". basename($pluginfile, '.pm'); require $pluginfile; my $plugin = $pluginclass->new(parent => $self); + + # index the fstypes + if ($plugin->does('ManaTools::Shared::disk_backend::FileSystem')) { + # add all types to link to this plugin + my $fstypes = $plugin->fstypes(); + for my $fstype (keys %{$fstypes}) { + $fs->{$fstype} = $fstypes->{$fstype}; + } + } + + # check dependencies if ($self->_check_dependencies($plugins, @{$plugin->dependencies()})) { push @{$plugins}, $plugin; } @@ -171,6 +183,18 @@ has 'parts' => ( } ); +has 'fs' => ( + is => 'ro', + isa => 'HashRef', + traits => ['Hash'], + default => sub { + return {}; + }, + handles => { + fstype => 'get', + } +); + #============================================================= diff --git a/lib/ManaTools/Shared/disk_backend/FileSystem.pm b/lib/ManaTools/Shared/disk_backend/FileSystem.pm index 3799686f..fec1847a 100644 --- a/lib/ManaTools/Shared/disk_backend/FileSystem.pm +++ b/lib/ManaTools/Shared/disk_backend/FileSystem.pm @@ -61,9 +61,11 @@ use Moose::Role; has 'fstypes' => ( is => 'ro', - isa => 'ArrayRef[Str]', + isa => 'HashRef[Str]', init_arg => undef, - default => sub { return []; }, + default => sub { + return {}; + }, ); #============================================================= @@ -91,7 +93,7 @@ sub has_type { my $self = shift; my $type = shift; my $fstypes = $self->fstypes(); - for my $t (@{$fstypes}) { + for my $t (keys %{$fstypes}) { if ($t eq $type) { return 1; } diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm index a7acdd6d..4c7cb707 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm @@ -60,7 +60,11 @@ extends 'ManaTools::Shared::disk_backend::Plugin'; with 'ManaTools::Shared::disk_backend::FileSystem'; has '+fstypes' => ( - default => sub { return ['btrfs'] }, + default => sub { + return { + 'btrfs' => 'Btrfs', + }; + }, ); has '+dependencies' => ( diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm index e7b4d9ed..4dc6de27 100644 --- a/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm +++ b/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm @@ -60,7 +60,13 @@ extends 'ManaTools::Shared::disk_backend::Plugin'; with 'ManaTools::Shared::disk_backend::FileSystem'; has '+fstypes' => ( - default => sub { return ['ext2', 'ext3', 'ext4']; }, + default => sub { + return { + 'ext2' => 'Extfs', + 'ext3' => 'Extfs', + 'ext4' => 'Extfs' + }; + }, ); has '+dependencies' => ( -- cgit v1.2.1