From 8719d7a373e56e8282a47eff174958282777d00e Mon Sep 17 00:00:00 2001
From: sergey ivanov <seriv@cs.umd.edu>
Date: Mon, 1 Jun 2020 17:28:34 -0400
Subject: [PATCH] check counts for snapshots

---
 lib/Site/ZFSSnapshot.pm | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/Site/ZFSSnapshot.pm b/lib/Site/ZFSSnapshot.pm
index ff77bea..342458c 100644
--- a/lib/Site/ZFSSnapshot.pm
+++ b/lib/Site/ZFSSnapshot.pm
@@ -57,23 +57,23 @@ sub handler {
     my ($when,$age) = (0,`date '+%s'`);
     chomp $age; $age -= $when;
     my $line = '';
+    my ($count,$list);
     my $LIST = "/usr/sbin/zfs list -H -p -o creation -S creation -d 1 -t snapshot $zfs 2>&1";
-    open (my $list, "-|", $LIST)or die "can't run $LIST: $!";
-    while (<$list>) {
+    open ($list, "-|", $LIST)or die "can't run $LIST: $!";
 =pod
 1469459040
 =cut
-      chomp;
+    if (($_ = <$list>) && ($_ =~ m/^(\d+)$/)){
+      $when = $1;
+      $age = `$DATE '+%s'` - $when; 
       $line = $_ if $_;
-      if (/^(\d+)$/){
-        $when = $1;
-        $age = `$DATE '+%s'` - $when; 
-        last;
-      }
+      while ( <$list> ) {};
+      $count = $.;
     }
     return {
-      "age"     => [$age,  "i"],
-      "line"    => [$line, "s"]
+      "age"     => [$age,   "i"],
+      "count"   => [$count, "i"],
+      "line"    => [$line,  "s"]
     }
 }
 
-- 
GitLab