Minor changes.

* scripts/tar-snapshot-edit: License under GPLv3+.
Remove trailing whitespace.
This commit is contained in:
Sergey Poznyakoff
2011-09-19 20:22:25 +03:00
parent a6cc856fbe
commit 8f70a3294c

View File

@@ -1,10 +1,10 @@
#! /usr/bin/perl -w #! /usr/bin/perl -w
# Display and edit the 'dev' field in tar's snapshots # Display and edit the 'dev' field in tar's snapshots
# Copyright (C) 2007,2011 Free Software Foundation, Inc. # Copyright (C) 2007, 2011 Free Software Foundation, Inc.
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option) # the Free Software Foundation; either version 3, or (at your option)
# any later version. # any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
@@ -93,11 +93,11 @@ sub read_incr_db_0 ($$) {
while (<$file>) { while (<$file>) {
/^(\+?)([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_"); /^(\+?)([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_");
if ( $1 eq "+" ) { if ( $1 eq "+" ) {
$nfs="1"; $nfs="1";
} else { } else {
$nfs="0"; $nfs="0";
} }
push @dirs, { nfs=>$nfs, push @dirs, { nfs=>$nfs,
dev=>$2, dev=>$2,
ino=>$3, ino=>$3,
@@ -124,11 +124,11 @@ sub read_incr_db_1 ($$) {
while (<$file>) { while (<$file>) {
/^(\+?)([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_"); /^(\+?)([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*) (.*)\n$/ || die("Bad snapshot line $_");
if ( $1 eq "+" ) { if ( $1 eq "+" ) {
$nfs="1"; $nfs="1";
} else { } else {
$nfs="0"; $nfs="0";
} }
push @dirs, { nfs=>$nfs, push @dirs, { nfs=>$nfs,
timestamp_sec=>$2, timestamp_sec=>$2,
@@ -229,9 +229,9 @@ sub validate_integer_field ($$$$) {
} else { } else {
if ( $field < $min ) { if ( $field < $min ) {
$msg = " $field_name value too low: \"$field\" < $min \n"; $msg = " $field_name value too low: \"$field\" < $min \n";
} elsif ( $field > $max ) { } elsif ( $field > $max ) {
$msg = " $field_name value too high: \"$field\" > $max \n"; $msg = " $field_name value too high: \"$field\" > $max \n";
} }
} }
return $msg; return $msg;
} }
@@ -289,13 +289,13 @@ sub check_field_values ($) {
$msg = ""; $msg = "";
$msg .= validate_integer_field($info->[1], $msg .= validate_integer_field($info->[1],
'timestamp_sec', $MIN_TIME_T, $MAX_TIME_T); 'timestamp_sec', $MIN_TIME_T, $MAX_TIME_T);
if ($snapver >= 1) { if ($snapver >= 1) {
$msg .= validate_integer_field($info->[2], $msg .= validate_integer_field($info->[2],
'timestamp_nsec', 0, $BILLION-1); 'timestamp_nsec', 0, $BILLION-1);
} }
if ( $msg ne "" ) { if ( $msg ne "" ) {
$error_found = 1; $error_found = 1;
print "\n shapshot file header:\n"; print "\n shapshot file header:\n";
print $msg; print $msg;
} }
@@ -306,25 +306,25 @@ sub check_field_values ($) {
$msg = ""; $msg = "";
$msg .= validate_integer_field($dir->{'nfs'}, 'nfs', 0, 1); $msg .= validate_integer_field($dir->{'nfs'}, 'nfs', 0, 1);
if ($snapver >= 1) { if ($snapver >= 1) {
$msg .= validate_integer_field($dir->{'timestamp_sec'}, $msg .= validate_integer_field($dir->{'timestamp_sec'},
'timestamp_sec', $MIN_TIME_T, $MAX_TIME_T); 'timestamp_sec', $MIN_TIME_T, $MAX_TIME_T);
$msg .= validate_integer_field($dir->{'timestamp_nsec'}, $msg .= validate_integer_field($dir->{'timestamp_nsec'},
'timestamp_nsec', 0, $BILLION-1); 'timestamp_nsec', 0, $BILLION-1);
} }
$msg .= validate_integer_field($dir->{'dev'}, 'dev', 0, $MAX_DEV_T); $msg .= validate_integer_field($dir->{'dev'}, 'dev', 0, $MAX_DEV_T);
$msg .= validate_integer_field($dir->{'ino'}, 'ino', 0, $MAX_INO_T); $msg .= validate_integer_field($dir->{'ino'}, 'ino', 0, $MAX_INO_T);
if ( $msg ne "" ) { if ( $msg ne "" ) {
$error_found = 1; $error_found = 1;
print "\n directory: $dir->{'name'}\n"; print "\n directory: $dir->{'name'}\n";
print $msg; print $msg;
} }
} }
print "\n Snapshot field value check complete" , print "\n Snapshot field value check complete" ,
$error_found ? "" : ", no errors found" , $error_found ? "" : ", no errors found" ,
".\n"; ".\n";
} }
## editing ## editing
@@ -336,12 +336,12 @@ sub replace_device_number ($@) {
my $count = 0; my $count = 0;
foreach my $dir (@{$info->[3]}) { foreach my $dir (@{$info->[3]}) {
foreach $x (@repl) { foreach $x (@repl) {
if ($dir->{'dev'} eq $$x[0]) { if ($dir->{'dev'} eq $$x[0]) {
$dir->{'dev'} = $$x[1]; $dir->{'dev'} = $$x[1];
$count++; $count++;
last; last;
} }
} }
} }
print " Updated $count records.\n" print " Updated $count records.\n"
@@ -377,9 +377,9 @@ sub write_incr_db_0 ($$) {
print $file "$timestamp_sec\n"; print $file "$timestamp_sec\n";
foreach my $dir (@{$info->[3]}) { foreach my $dir (@{$info->[3]}) {
if ($dir->{'nfs'}) { if ($dir->{'nfs'}) {
print $file '+' print $file '+'
} }
print $file "$dir->{'dev'} "; print $file "$dir->{'dev'} ";
print $file "$dir->{'ino'} "; print $file "$dir->{'ino'} ";
print $file "$dir->{'name'}\n"; print $file "$dir->{'name'}\n";
@@ -398,9 +398,9 @@ sub write_incr_db_1 ($$) {
print $file "$timestamp_sec $timestamp_nsec\n"; print $file "$timestamp_sec $timestamp_nsec\n";
foreach my $dir (@{$info->[3]}) { foreach my $dir (@{$info->[3]}) {
if ($dir->{'nfs'}) { if ($dir->{'nfs'}) {
print $file '+' print $file '+'
} }
print $file "$dir->{'timestamp_sec'} "; print $file "$dir->{'timestamp_sec'} ";
print $file "$dir->{'timestamp_nsec'} "; print $file "$dir->{'timestamp_nsec'} ";
print $file "$dir->{'dev'} "; print $file "$dir->{'dev'} ";
@@ -441,7 +441,7 @@ sub main {
our ($opt_b, $opt_r, $opt_h, $opt_c); our ($opt_b, $opt_r, $opt_h, $opt_c);
getopts('br:hc'); getopts('br:hc');
HELP_MESSAGE() if ($opt_h || $#ARGV == -1 || ($opt_b && !$opt_r) || HELP_MESSAGE() if ($opt_h || $#ARGV == -1 || ($opt_b && !$opt_r) ||
($opt_r && $opt_c) ); ($opt_r && $opt_c) );
my @repl; my @repl;
if ($opt_r) { if ($opt_r) {
@@ -488,7 +488,7 @@ Usage:
With -c: Check the field values in each SNAPFILE and print warning With -c: Check the field values in each SNAPFILE and print warning
messages if any invalid values are found. (An invalid value is one messages if any invalid values are found. (An invalid value is one
that would cause \"tar\" to generate an that would cause \"tar\" to generate an
Unexpected field value in snapshot file Unexpected field value in snapshot file
error message as it processed the snapshot file.) error message as it processed the snapshot file.)
EOF EOF