Przeglądaj źródła

Updated to 0.14

Paul Trost 10 lat temu
rodzic
commit
4b5d9750f7
3 zmienionych plików z 9 dodań i 5 usunięć
  1. 3 0
      Changes
  2. BIN
      dist/Disk-SMART-0.14.tar.gz
  3. 6 5
      lib/Disk/SMART.pm

+ 3 - 0
Changes

@@ -1,5 +1,8 @@
 Revision history for Disk-SMART
 
+0.14	2015-06-14
+	Fixed to run unit tests without smartctl binary being installed
+
 0.13	2015-06-12
 	Removed bad mocking code from module and unit tests and refactored to use Test::MockModule
 	Refactored getting smart output into subroutine

BIN
dist/Disk-SMART-0.14.tar.gz


+ 6 - 5
lib/Disk/SMART.pm

@@ -8,7 +8,7 @@ use Math::Round;
 use File::Which;
 
 {
-    $Disk::SMART::VERSION = '0.13'
+    $Disk::SMART::VERSION = '0.14'
 }
 
 our $smartctl = which('smartctl');
@@ -53,8 +53,6 @@ sub new {
 
     croak "Valid device identifier not supplied to constructor for $class.\n"
         if !@devices;
-    croak "smartctl binary was not found on your system, are you running as root?\n"
-        if !-f $smartctl;
 
     $self->update_data(@devices);
 
@@ -259,14 +257,17 @@ sub update_data {
 sub _get_smart_output {
     my ( $device, $options ) = @_;
     $options = $options // '';
+
+    die "smartctl binary was not found on your system, are you running as root?\n"
+        if ( !defined $smartctl || !-f $smartctl );
+
     open my $fh, '-|', "$smartctl $device $options" or confess "Can't run smartctl binary\n";
     local $/ = undef;
     my $smart_output = <$fh>;
-    #close $fh or confess "Can't close file handle reading smartctl output\n";
+
     if ( $smart_output =~ /Unknown USB bridge/ ) {
         open $fh, '-|', "$smartctl $device $options -d sat" or confess "Can't run smartctl binary\n";
         $smart_output = <$fh>;
-        close $fh or confess "Can't close file handle reading smartctl output\n";
     }
     return $smart_output;
 }