check for error while listing snapshots/bookmarks as this can be dangerous with force-delete

This commit is contained in:
Christoph Klaffl 2018-07-30 09:43:03 +02:00
parent 1cb1209c78
commit 020f57cb74
No known key found for this signature in database
GPG Key ID: FC1C525C2A47CC28
1 changed files with 13 additions and 3 deletions

16
syncoid
View File

@ -1114,7 +1114,7 @@ sub getsnaps() {
if ($debug) { print "DEBUG: getting list of snapshots on $fs using $getsnapcmd...\n"; }
open FH, $getsnapcmd;
my @rawsnaps = <FH>;
close FH;
close FH or die "CRITICAL ERROR: snapshots couldn't be listed for $fs (exit code $?)";
# this is a little obnoxious. get guid,creation returns guid,creation on two separate lines
# as though each were an entirely separate get command.
@ -1158,11 +1158,21 @@ sub getbookmarks() {
$fsescaped = escapeshellparam($fsescaped);
}
my $getbookmarkcmd = "$rhost $mysudocmd $zfscmd get -Hpd 1 -t bookmark guid,creation $fsescaped |";
my $error = 0;
my $getbookmarkcmd = "$rhost $mysudocmd $zfscmd get -Hpd 1 -t bookmark guid,creation $fsescaped 2>&1 |";
if ($debug) { print "DEBUG: getting list of bookmarks on $fs using $getbookmarkcmd...\n"; }
open FH, $getbookmarkcmd;
my @rawbookmarks = <FH>;
close FH;
close FH or $error = 1;
if ($error == 1) {
if ($rawbookmarks[0] =~ /invalid type/) {
# no support for zfs bookmarks, return empty hash
return %bookmarks;
}
die "CRITICAL ERROR: bookmarks couldn't be listed for $fs (exit code $?)";
}
# this is a little obnoxious. get guid,creation returns guid,creation on two separate lines
# as though each were an entirely separate get command.