Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / Tapelist.pm
index 6a746ba623e6df860027e927dcf3f6f0f716cda0..6bc5fbd3603351d4ecb0a9ea7b229ec46d273f04 100644 (file)
@@ -1,5 +1,5 @@
 # This file was automatically generated by SWIG (http://www.swig.org).
-# Version 1.3.39
+# Version 2.0.4
 #
 # Do not make changes to this file unless you know what you are doing--modify
 # the SWIG interface file instead.
@@ -309,16 +309,37 @@ sub remove_tapelabel {
 
 sub add_tapelabel {
     my $self = shift;
-    my ($datestamp, $label, $comment, $reuse) = @_;
+    my ($datestamp, $label, $comment, $reuse, $meta, $barcode, $blocksize) = @_;
     $reuse = 1 if !defined $reuse;
 
     # prepend this (presumably new) volume to the beginning of the list
-    unshift @{$self->{'tles'}}, {
-       'datestamp' => $datestamp,
-       'label' => $label,
-       'reuse' => $reuse,
-       'comment' => $comment,
+    my $tle = {
+        'datestamp' => $datestamp,
+        'label'     => $label,
+        'reuse'     => $reuse,
+        'barcode'   => $barcode,
+        'meta'      => $meta,
+        'blocksize' => $blocksize,
+        'comment'   => $comment,
     };
+    my $tles = $self->{'tles'};
+    if (!defined $tles->[0] ||
+       $tles->[0]->{'datestamp'} le $datestamp) {
+       unshift @{$tles}, $tle;
+    } elsif (defined $tles->[0] &&
+       $tles->[@$tles-1]->{'datestamp'} gt $datestamp) {
+       push @{$tles}, $tle;
+    } else {
+       my $added = 0;
+       for my $i (0..(@$tles-1)) {
+           if ($tles->[$i]->{'datestamp'} le $datestamp) {
+               splice @{$tles}, $i, 0, $tle;
+               $added = 1;
+               last;
+           }
+       }
+       push @{$tles}, $tle if !$added;
+    }
     $self->_update_positions();
 }
 
@@ -335,8 +356,11 @@ sub write {
        my $datestamp = $tle->{'datestamp'};
        my $label = $tle->{'label'};
        my $reuse = $tle->{'reuse'} ? 'reuse' : 'no-reuse';
+       my $barcode = (defined $tle->{'barcode'})? (" BARCODE:" . $tle->{'barcode'}) : '';
+       my $meta = (defined $tle->{'meta'})? (" META:" . $tle->{'meta'}) : '';
+       my $blocksize = (defined $tle->{'blocksize'})? (" BLOCKSIZE:" . $tle->{'blocksize'}) : '';
        my $comment = (defined $tle->{'comment'})? (" #" . $tle->{'comment'}) : '';
-       $result &&= print $fhn "$datestamp $label $reuse$comment\n";
+       $result &&= print $fhn "$datestamp $label $reuse$barcode$meta$blocksize$comment\n";
     }
     my $result_close = close($fhn);
     $result &&= $result_close;
@@ -388,13 +412,18 @@ sub _read_tapelist {
     my @tles;
     open(my $fh, "<", $self->{'filename'}) or return $self;
     while (my $line = <$fh>) {
-       my ($datestamp, $label, $reuse, $comment)
-           = $line =~ m/^([0-9]*)\s([^\s]*)\s(reuse|no-reuse)\s*(?:\#(.*))?$/mx;
-       next if !defined $datestamp; # silently filter out bogus lines
+       my ($datestamp, $label, $reuse, $barcode, $meta, $blocksize, $comment)
+           = $line =~ m/^([0-9]+)\s*([^\s]*)\s*(?:(reuse|no-reuse))?\s*(?:BARCODE:([^\s]*))?\s*(?:META:([^\s]*))?\s*(?:BLOCKSIZE:([^\s]*))?\s*(?:\#(.*))?$/mx;
+       if (!defined $datestamp) {
+           Amanda::Debug::critical("Bogus line in the tapelist ($self->{'filename'}) file: $line");
+       }
        push @tles, {
            'datestamp' => $datestamp,
            'label' => $label,
-           'reuse' => ($reuse eq 'reuse'),
+           'reuse' => (!defined $reuse || $reuse eq 'reuse'),
+           'barcode' => $barcode,
+           'meta' => $meta,
+           'blocksize' => $blocksize,
            'comment' => $comment,
        };
     }