Gracefully handle error when source dataset disappeared

If the source dataset dissappeared before we were able to get the
sanoid:sync property, do not set an error exit code.  Handle this
gracefully as this should not be considered an error.

Fixes #380
This commit is contained in:
Michael Schout 2019-05-16 11:38:39 -05:00
parent 681820ceab
commit fd71e794ad
1 changed files with 35 additions and 1 deletions

36
syncoid
View File

@ -290,7 +290,10 @@ sub syncdataset {
if (!defined $sync) {
# zfs already printed the corresponding error
if ($exitcode < 2) { $exitcode = 2; }
if (dataset_exists($sourcehost, $sourcefs, $sourceisroot) and $exitcode < 2) {
$exitcode = 2;
}
return 0;
}
@ -1147,6 +1150,37 @@ sub getzfsvalue {
return $value;
}
sub dataset_exists {
my ($rhost, $fs, $isroot) = @_;
my $fsescaped = escapeshellparam($fs);
my $mysudocmd;
if ($isroot) {
$mysudocmd = '';
}
else {
$mysudocmd = $sudocmd;
}
my $command = "$rhost $mysudocmd $zfscmd get -H creation $fsescaped";
if ($debug) {
print "$command\n";
}
open my $fh, '-|', "$command 2>&1";
my $result = <$fh>;
close $fh;
if ($result =~ /dataset does not exist/) {
warn "$fsescaped does not exist...\n";
return 0;
}
return 1;
}
sub readablebytes {
my $bytes = shift;
my $disp;