make dir_is_empty a proper sub

this allows us later to mock the sub,
which we need for testing

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2016-10-17 10:29:10 +02:00
committed by Dietmar Maurer
parent 461a9fd8da
commit 10a48db55c

View File

@ -324,6 +324,21 @@ sub get_wear_leveling_info {
return $wearout;
}
sub dir_is_empty {
my ($dir) = @_;
my $dh = IO::Dir->new ($dir);
return 1 if !$dh;
while (defined(my $tmp = $dh->read)) {
next if $tmp eq '.' || $tmp eq '..';
$dh->close;
return 0;
}
$dh->close;
return 1;
}
sub get_disks {
my ($disk, $nosmart) = @_;
my $disklist = {};
@ -342,21 +357,6 @@ sub get_disks {
return $mounted->{$dev};
};
my $dir_is_empty = sub {
my ($dir) = @_;
my $dh = IO::Dir->new ($dir);
return 1 if !$dh;
while (defined(my $tmp = $dh->read)) {
next if $tmp eq '.' || $tmp eq '..';
$dh->close;
return 0;
}
$dh->close;
return 1;
};
my $journalhash = get_ceph_journals();
my $zfslist = get_zfs_devices();
@ -479,7 +479,7 @@ sub get_disks {
$journal_count++ if $journalhash->{"$partpath/$part"};
if (!&$dir_is_empty("$sysdir/$part/holders") && !$found_lvm) {
if (!dir_is_empty("$sysdir/$part/holders") && !$found_lvm) {
$found_dm = 1;
}
});
@ -493,7 +493,7 @@ sub get_disks {
# multipath, software raid, etc.
# this check comes in last, to show more specific info
# if we have it
$used = 'Device Mapper' if !$used && !&$dir_is_empty("$sysdir/holders");
$used = 'Device Mapper' if !$used && !dir_is_empty("$sysdir/holders");
$disklist->{$dev}->{used} = $used if $used;
$disklist->{$dev}->{osdid} = $osdid;