Преглед на файлове

Added confess in new() in case smartctl cannot find the specified drive.

Paul Trost преди 11 години
родител
ревизия
ddf0d3d24c
променени са 4 файла, в които са добавени 11 реда и са изтрити 1 реда
  1. 3 0
      Changes
  2. 1 0
      ignore.txt
  3. 6 1
      lib/Disk/SMART.pm
  4. 1 0
      t/01-instantiation.t

+ 3 - 0
Changes

@@ -1,5 +1,8 @@
 Revision history for Disk-SMART
 
+0.02    2014-10-03
+        Added confess to new() in case smartctl cannot find the specified device
+
 0.01    2014-10-03
         First version, released on an unsuspecting world.
 

+ 1 - 0
ignore.txt

@@ -10,3 +10,4 @@ pm_to_blib*
 cover_db
 pod2htm*.tmp
 Disk-SMART-*
+.gitignore

+ 6 - 1
lib/Disk/SMART.pm

@@ -52,7 +52,12 @@ sub new {
     my $self = bless {}, $class;
 
     foreach my $device (@devices) {
-        $self->{'devices'}->{$device}->{'SMART_OUTPUT'} = qx($smartctl -a $device);
+        my $out = qx($smartctl -a $device);
+        if ( $out =~ /No such device/i ) {
+            confess "Device $device could not be found\n";
+            next;
+        }
+        $self->{'devices'}->{$device}->{'SMART_OUTPUT'} = $out;
     }
 
     return $self;

+ 1 - 0
t/01-instantiation.t

@@ -4,4 +4,5 @@ use Test::More 'tests' => 1;
 use Disk::SMART;
 
 my $smart = Disk::SMART->new('/dev/sda');
+
 pass('instantiation of object successful') if (defined($smart));