| 1 | # Copyright (c) 2024-2026 Philipp Schafft <lion@cpan.org> | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: generic module for extracting information from filesystems | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package File::Information::Filesystem; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use parent 'File::Information::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | our $VERSION = v0.17; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | my @_copy_properties = ( | |||||||||||||||||||||||||||
| 21 | qw(dos_device dos_path), | ||||||||||||||||||||||||||||
| 22 | qw(mountpoint fs_type), | ||||||||||||||||||||||||||||
| 23 | qw(linux_mount_options linux_superblock_options), | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | my %_properties = ( | ||||||||||||||||||||||||||||
| 27 | dev_disk_by_uuid => {rawtype => 'uuid'}, | ||||||||||||||||||||||||||||
| 28 | dev_disk_by_label => {}, | ||||||||||||||||||||||||||||
| 29 | dev_name => {}, | ||||||||||||||||||||||||||||
| 30 | dev_mapper_name => {}, | ||||||||||||||||||||||||||||
| 31 | 3 | (map {$_ => {}} | |||||||||||||||||||||||||||
| 32 | @_copy_properties, | ||||||||||||||||||||||||||||
| 33 | ), | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | my %_known_paths = ( | |||||||||||||||||||||||||||
| 37 | '/dev/disk/by-uuid' => 'uuid', | ||||||||||||||||||||||||||||
| 38 | '/dev/disk/by-label' => 'label', | ||||||||||||||||||||||||||||
| 39 | '/dev/mapper' => 'mapper', | ||||||||||||||||||||||||||||
| 40 | '/dev' => 'dev', | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub _new { | ||||||||||||||||||||||||||
|
Subroutine
_new: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($pkg, %opts) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | my $self = $pkg->SUPER::_new(%opts, properties => \%_properties); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $pv = ($self->{properties_values} //= {})->{current} //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
$self->{"properties_values"} //= {}
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Truth table0%0/2
A
A= $self->{"properties_values"}
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | croak 'No stat or dirstat is given' unless defined($self->{stat}) || defined($self->{dirstat}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"stat"} or defined $self->{"dirstat"}
MC/DC0%0/2
defined $self->{"stat"} or defined $self->{"dirstat"}
defined $self->{"stat"}
defined $self->{"dirstat"}
Truth table0%0/3
A or B
A= defined $self->{"stat"}B= defined $self->{"dirstat"}
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | croak 'No paths is given' unless defined $self->{paths}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | foreach my $key (keys %{$self->{paths}}) { | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $known = $_known_paths{$key} or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | foreach my $value (@{$self->{paths}{$key}}) { | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($known eq 'uuid') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($value =~ __PACKAGE__->SUPER::RE_UUID) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $pv->{dev_disk_by_uuid} = {raw => $value}; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } elsif ($known eq 'label') { | ||||||||||||||||||||||||||||
| 59 | 0 | $pv->{dev_disk_by_label} = {raw => $value}; | |||||||||||||||||||||||||||
| 60 | } elsif ($known eq 'dev') { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $pv->{dev_name} //= {raw => $value}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$pv->{"dev_name"} //= {"raw", $value}
MC/DC0%0/1
$pv->{"dev_name"} //= {"raw", $value}
$pv->{"dev_name"}
Truth table0%0/2
A
A= $pv->{"dev_name"}
| |||||||||||||||||||||||||||||
| 62 | } elsif ($known eq 'mapper') { | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $pv->{dev_mapper_name} //= {raw => $value}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$pv->{"dev_mapper_name"} //= {"raw", $value}
MC/DC0%0/1
$pv->{"dev_mapper_name"} //= {"raw", $value}
$pv->{"dev_mapper_name"}
Truth table0%0/2
A
A= $pv->{"dev_mapper_name"}
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Simple keys: | ||||||||||||||||||||||||||||
| 69 | 0 | foreach my $key (@_copy_properties) { | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (defined $self->{$key}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $pv->{$key} = {raw => $self->{$key}}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | return $self; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # ---------------- | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _default_device_search_paths { | ||||||||||||||||||||||||||
|
Subroutine
_default_device_search_paths: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 81 | 0 | return state $defaults = [qw(/dev /dev/disk/by-id /dev/mapper), keys %_known_paths]; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | 1; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||