Skip to content

Commit e9e388b

Browse files
committed
Merge pull request #55 from hadfl/snapshot_improvement
- snapshot creation optimised...
2 parents 432f414 + 023b41e commit e9e388b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/ZnapZend/ZFS.pm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,22 @@ sub listSubDataSets {
174174
sub createSnapshot {
175175
my $self = shift;
176176
my $dataSet = shift;
177-
my $remote;
178177
my @recursive = $_[0] ? ('-r') : ();
179-
180-
#check if snapshot already exists, if so, exit.
181-
return 0 if $self->snapshotExists($dataSet);
178+
my $remote;
182179

183180
($remote, $dataSet) = $splitHostDataSet->($dataSet);
184181
my @ssh = $self->$buildRemote($remote, [qw(zfs snapshot), @recursive, $dataSet]);
185182

186183
print STDERR '# ' . join(' ', @ssh) . "\n" if $self->debug;
187-
system(@ssh) && die "ERROR: cannot create snapshot $dataSet\n" if !$self->noaction;
188184

189-
return 1;
185+
#return if 'noaction' or snapshot creation successful
186+
return 1 if $self->noaction || !system(@ssh);
187+
188+
#check if snapshot already exists and therefore creation failed
189+
return 0 if $self->snapshotExists($dataSet);
190+
191+
#creation failed and snapshot does not exist, throw an exception
192+
die "ERROR: cannot create snapshot $dataSet\n";
190193
}
191194

192195
# known limitation: snapshots from subdatasets have to be destroyed individually

0 commit comments

Comments
 (0)