From 10a48db55c642155e25a4ac2cd7347915f8f918e Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 17 Oct 2016 10:29:10 +0200 Subject: [PATCH] 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 --- PVE/Diskmanage.pm | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/PVE/Diskmanage.pm b/PVE/Diskmanage.pm index dd2591c..ad1a896 100644 --- a/PVE/Diskmanage.pm +++ b/PVE/Diskmanage.pm @@ -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; -- 2.39.2