[pve-devel] [PATCH storage 3/5] make dir_is_empty a proper sub

Dominik Csapak d.csapak at proxmox.com
Mon Oct 17 10:29:10 CEST 2016


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

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 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.1.4





More information about the pve-devel mailing list