save the edited file, not the parsed and niced one
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Sat, 24 May 2014 23:16:42 +0200
changeset 16 1cbe9dc60243
parent 15 aa1598910bb0
child 17 86d2b0d707bf
save the edited file, not the parsed and niced one
bin/dnsvi
lib/DNS/Vi.pm
--- a/bin/dnsvi	Sat May 24 23:01:17 2014 +0200
+++ b/bin/dnsvi	Sat May 24 23:16:42 2014 +0200
@@ -6,6 +6,7 @@
 use if $ENV{DEBUG} // '' eq 'dnsvi' => 'Smart::Comments';
 use Getopt::Long;
 use Pod::Usage;
+use File::Copy;
 
 use blib;
 use DNS::Vi;
@@ -51,12 +52,13 @@
 
     my @zone1 = parse($_ = `@dig`, { -skip => $o{skip} } )
       or die "Empty zone\n";
+    my $fh2;
     my @zone2 = do {
 	if (my $file = shift @ARGV) {
 	    parse(slurp($file), { -skip => $o{skip} });
 	} 
 	else {
-	    edit(@zone1, { -skip => $o{skip}, -editor => $o{editor} });
+	    edit(@zone1, { -skip => $o{skip}, -editor => $o{editor}, -backup => \$fh2 });
 	}
     };
     ### @zone2
@@ -78,8 +80,9 @@
 	-debug => $o{debug},
 	-key => $o{key}})
     or do { 
-	save(\@zone2, ",dnsvi-$$")
-	and say "Saved as ',dnsvi-$$'";
+	copy($fh2->filename, ",dnsvi-$$")
+	and say "Saved as ',dnsvi-$$'"
+	    if $fh2;
     };
 
     return 0;
@@ -95,12 +98,13 @@
 
 =head1 SYNOPSIS
 
- vidns [-l] [-k key] [-s server] [-d] <zone> [<file>]
+ vidns [[-l] | [[-k key] [-s server]]] [-d] <zone> [<file>]
 
 =head1 DESCRIPTION
 
-This tools supports you in maintaining a dynamic
-zone.
+This tools supports you in maintaining a dynamic zone. Normally you'll
+use it with the name of zone. For batch mode you may use it with an
+additional parameter, die edited zone file.
 
 =head2 OPTIONS
 
@@ -121,6 +125,10 @@
 The name of the key file we need for TSIG (the AXFR will use it,
 as well as the update).
 
+=item B<-d>
+
+This option enables debugging of C<nsupdate>. (default: off)
+
 =back
 
 =head1 PREREQUISITES
--- a/lib/DNS/Vi.pm	Sat May 24 23:01:17 2014 +0200
+++ b/lib/DNS/Vi.pm	Sat May 24 23:16:42 2014 +0200
@@ -8,7 +8,7 @@
 
 use base 'Exporter';
 
-our @EXPORT = qw(ttl2h h2ttl parse delta nice edit update show save);
+our @EXPORT = qw(ttl2h h2ttl parse delta nice edit update show);
 our @EXPORT_OK = ();
 
 sub parse {
@@ -187,6 +187,7 @@
     $tmp->flush();
     system $arg{-editor} => $tmp->filename;
     $tmp->seek(0, 0);
+    ${$arg{-backup}} = $tmp if $arg{-backup};
     return parse(do { local $/ = undef; <$tmp>}, {-skip => $arg{-skip}});
 }