]> git.proxmox.com Git - pve-storage.git/commitdiff
make dir_is_empty a proper sub
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 17 Oct 2016 08:29:10 +0000 (10:29 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Oct 2016 08:19:40 +0000 (10:19 +0200)
this allows us later to mock the sub,
which we need for testing

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Diskmanage.pm

index dd2591c70d8e32c434f9f7c25792fcb6b806d632..ad1a896fec4b9671d0cd0944725085e07a26af5a 100644 (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;