Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / Application / Zfs.pm
index 551366f48a37e23ea724e730253cea8cb960adc2..ecd9b13c2d6b61dbf91810ca91e9f16cb9ee65ef 100644 (file)
@@ -1,8 +1,9 @@
-# Copyright (c) 2008,2009 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -38,7 +39,7 @@ sub zfs_set_value {
     my $self = shift;
 
     if (defined $self->{execute_where} && $self->{execute_where} ne "client") {
-       $self->print_to_server_and_die(" Script must be run on the client 'execute_where client'", $Amanda::Script_App::ERROR);
+       $self->print_to_server_and_die(" Script must be run on the client 'execute-where client'", $Amanda::Script_App::ERROR);
     }
     if ($self->{df_path} ne "df" && !-e $self->{df_path}) {
        $self->print_to_server_and_die("Can't execute DF-PATH '$self->{df_path}' command",
@@ -197,11 +198,7 @@ sub zfs_set_value {
 
     }
 
-    if ($self->{action} eq 'check') {
-      $self->{snapshot} = $self->zfs_build_snapshotname($device, -1);
-    } else {
-      $self->{snapshot} = $self->zfs_build_snapshotname($device);
-    }
+    $self->{snapshot} = $self->zfs_build_snapshotname($device);
     if (defined $self->{mountpoint}) {
        if ($device =~ /^$self->{mountpoint}/) {
             $self->{dir} = $device;
@@ -310,7 +307,7 @@ sub zfs_rename_snapshot {
     my $device = $self->{device};
     $device = $self->{directory} if defined $self->{directory};
     my $newsnapshotname = $self->zfs_build_snapshotname($device, $level);
-    my $cmd = "$self->{pfexec_cmd} $self->{zfs_path} rename $self->{filesystem}\@$self->{snapshot} $newsnapshotname";
+    my $cmd = "$self->{pfexec_cmd} $self->{zfs_path} rename $self->{filesystem}\@$self->{snapshot} $self->{filesystem}\@$newsnapshotname";
     debug "running: $cmd|";
     my($wtr, $rdr, $err, $pid);
     my($msg, $errmsg);
@@ -380,15 +377,13 @@ sub zfs_build_snapshotname {
 
     my $snapshotname = "";
 
-    if (!defined $level) {
-      $snapshotname = "amanda-" . Amanda::Util::sanitise_filename($self->{disk}) . "-current";
-    } else {
-      if ($level < 0) {
+    if ($self->{action} eq 'check') {
        $snapshotname = "amanda-" . Amanda::Util::sanitise_filename($self->{disk}) . "-check";
-      } else {
-        $snapshotname = "amanda-" . Amanda::Util::sanitise_filename($self->{disk}) . "-" . $level;
-      }
-    } 
+    } elsif (!defined $level) {
+       $snapshotname = "amanda-" . Amanda::Util::sanitise_filename($self->{disk}) . "-current";
+    } else {
+       $snapshotname = "amanda-" . Amanda::Util::sanitise_filename($self->{disk}) . "-" . $level;
+    }
 
     return $snapshotname;
 }