pf-tools commit: r900 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Net.pm lib/PFTools/Utils.pm lib/PFTools/VCS.pm sbin/fix_hosts sbin/mk_dhcp sbin/mk_interfaces sbin/mk_sitezone
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Wed Sep 8 13:03:09 UTC 2010
Author: ccaillet-guest
Date: Wed Sep 8 13:02:52 2010
New Revision: 900
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=900
Log:
* use remove_tree only if $co_dir exists
* fix Get_source: hostname IS NOT mandatory
* use IO::File in sbin/*
Modified:
branches/next-gen/debian/changelog
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Net.pm
branches/next-gen/lib/PFTools/Utils.pm
branches/next-gen/lib/PFTools/VCS.pm
branches/next-gen/sbin/fix_hosts
branches/next-gen/sbin/mk_dhcp
branches/next-gen/sbin/mk_interfaces
branches/next-gen/sbin/mk_sitezone
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=900&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Wed Sep 8 13:02:52 2010
@@ -11,8 +11,11 @@
[ Christophe Caillet ]
* use remove_tree with keep_root option instead of remove_tree + make_path
-
- -- Christophe Caillet <tof at sitadelle.com> Wed, 08 Sep 2010 10:06:41 +0200
+ * use remove_tree only if $co_dir exists
+ * fix Get_source: hostname IS NOT mandatory
+ * use IO::File in sbin/*
+
+ -- Christophe Caillet <quadchris at free.fr> Wed, 08 Sep 2010 15:00:52 +0200
pf-tools (1.0-1) unstable; urgency=low
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=900&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Wed Sep 8 13:02:52 2010
@@ -229,7 +229,7 @@
sub Get_source {
my ( $source, $hostname, $hash_subst, $pf_config ) = @_;
- return unless $source and $hostname;
+ return unless $source;
unless ($hash_subst) {
$hash_subst = Init_SUBST( $hostname, $pf_config );
@@ -306,7 +306,6 @@
$merge->{$section} = $hash_to_merge->{$section};
}
}
-
return $merge;
}
@@ -330,7 +329,6 @@
$global_parsed->{$section} = $hash_to_merge->{$section};
next;
}
-
my $tmp_merged
= __Merge_conf_includes(
$hash_to_merge->{$section}->{'__content'},
@@ -408,7 +406,6 @@
}
my $sect_type = $parsed->{$section}->{$select};
if ( $sect_type eq 'include' ) {
-
# We need to dive into deep ...
$parsed->{$section}->{'__content'}
= Load_conf(
Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=900&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Wed Sep 8 13:02:52 2010
@@ -74,16 +74,6 @@
. $type
. " defintion";
}
- elsif ( $net_hash->{ 'netmask' . $suffix } =~ /^\// ) {
- @net_def = ( $net_hash->{ 'network' . $suffix }
- . $net_hash->{ 'netmask' . $suffix } );
- $msg
- = "Invalid network "
- . $net_hash->{ 'network' . $suffix }
- . $net_hash->{ 'netmask' . $suffix } . " "
- . $type
- . " defintion";
- }
else {
@net_def = (
$net_hash->{ 'network' . $suffix },
Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=900&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Wed Sep 8 13:02:52 2010
@@ -88,20 +88,16 @@
$global_store_file = $pf_config->{'path'}->{'global_struct'}
if ( $global_store_file eq '' );
- if ( !-e $global_store_file || ( defined $reload && $reload ) ) {
-
- # print "Forcing reload or no storable available\n";
+ if ( !-e $global_store_file || $reload ) {
my $source
= Get_source( 'COMMON:/' . $pf_config->{'path'}->{'start_file'},
$hostname, {}, $pf_config );
- if ( !-e $source ) {
- Set_deferredlog();
- if ( !VCS_checkout( $hostname, $pf_config, {} ) ) {
- Abort( $CODE->{'EXEC'},
- "Unable to checkout configuration from VCS system" );
- }
- Unset_deferredlog();
- }
+ Set_deferredlog();
+ if ( ! VCS_checkout( $hostname, $pf_config, {} ) ) {
+ Abort( $CODE->{'EXEC'},
+ "Unable to checkout configuration from VCS system" );
+ }
+ Unset_deferredlog();
$global_struct
= Init_GLOBAL_NETCONFIG( $source, $hostname, $pf_config );
Flush2disk_GLOBAL( $global_struct, $pf_config );
Modified: branches/next-gen/lib/PFTools/VCS.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/VCS.pm?rev=900&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/VCS.pm (original)
+++ branches/next-gen/lib/PFTools/VCS.pm Wed Sep 8 13:02:52 2010
@@ -86,7 +86,14 @@
print $cvs_cmd. "\n" if ( $options->{'debug'} || $options->{'verbose'} );
my $co_dir = $pf_config->{'path'}->{'checkout_dir'};
- remove_tree($co_dir, { keep_root => 1 });
+ if ( -e $co_dir ) {
+ remove_tree $co_dir
+ or Abort ( $CODE->{'OPEN'},
+ "Unable to remove the content of $co_dir before checking out" );
+ }
+ make_path $co_dir
+ or Abort( $CODE->{'OPEN'},
+ "Unable to create path $co_dir for checking out" );
$ret = deferredlogsystem( "cd '" . $co_dir . "';" . $cvs_cmd );
if ($ret) {
@@ -136,7 +143,14 @@
print $svn_cmd. "\n" if ( $options->{'debug'} || $options->{'verbose'} );
my $co_dir = $pf_config->{'path'}->{'checkout_dir'};
- remove_tree($co_dir, { keep_root => 1 });
+ if ( -e $co_dir ) {
+ remove_tree $co_dir
+ or Abort ( $CODE->{'OPEN'},
+ "Unable to remove the content of $co_dir before checking out" );
+ }
+ make_path $co_dir
+ or Abort( $CODE->{'OPEN'},
+ "Unable to create path $co_dir for checking out" );
$ret = deferredlogsystem( "cd '" . $co_dir . "';" . $svn_cmd );
if ($ret) {
Modified: branches/next-gen/sbin/fix_hosts
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/fix_hosts?rev=900&op=diff
==============================================================================
--- branches/next-gen/sbin/fix_hosts (original)
+++ branches/next-gen/sbin/fix_hosts Wed Sep 8 13:02:52 2010
@@ -27,6 +27,7 @@
use Data::Dumper;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
+use IO::File;
use Sys::Hostname;
use PFTools::Logger;
@@ -132,10 +133,15 @@
Abort( $CODE->{'EXEC'},
"An error occured during fixing file " . $OUTPUT_FILE );
}
-unless ( open( FIXED, ">" . $OUTPUT_FILE ) ) {
- Abort( $CODE->{'OPEN'}, "Unable to open output file " . $OUTPUT_FILE );
-}
-print FIXED join( "", @{$fixed_input} );
-close(FIXED);
+
+my $output_fh = IO::File->new("> $OUTPUT_FILE")
+ or Abort( $CODE->{'OPEN'},
+ "Unable to open destination file $OUTPUT_FILE: $OS_ERROR" );
+$output_fh->print ( join '', @{$fixed_input} )
+ or Abort ( $CODE->{'OPEN'},
+ "Unable to write to destination file $OUTPUT_FILE: $OS_ERROR" );
+$output_fh->close()
+ or Abort( $CODE->{'OPEN'},
+ "Unable to close destination file $OUTPUT_FILE: $OS_ERROR" );
exit 0;
Modified: branches/next-gen/sbin/mk_dhcp
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_dhcp?rev=900&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_dhcp (original)
+++ branches/next-gen/sbin/mk_dhcp Wed Sep 8 13:02:52 2010
@@ -26,6 +26,7 @@
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
+use IO::File;
use PFTools::Logger;
use PFTools::Utils;
@@ -100,10 +101,15 @@
}
my $DHCP = Mk_dhcp( $HEADER, $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$SITE} );
-unless ( open( DHCP, ">" . $OUTPUT_FILE ) ) {
- Abort( $CODE->{'OPEN'}, "Unable to open zone file " . $OUTPUT_FILE );
-}
-print DHCP join( "\n", @{$DHCP} );
-close(DHCP);
+
+my $output_fh = IO::File->new ( '>' . $OUTPUT_FILE )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to open destination file $OUTPUT_FILE: $OS_ERROR" );
+$output_fh->print ( join "\n", @{$DHCP} )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to write to destination file $OUTPUT_FILE: $OS_ERROR" );
+$output_fh->close()
+ or Abort( $CODE->{'OPEN'},
+ "Unable to close destination file $OUTPUT_FILE: $OS_ERROR" );
exit 0;
Modified: branches/next-gen/sbin/mk_interfaces
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_interfaces?rev=900&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_interfaces (original)
+++ branches/next-gen/sbin/mk_interfaces Wed Sep 8 13:02:52 2010
@@ -25,6 +25,7 @@
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
+use IO::File;
use Sys::Hostname;
use PFTools::Logger;
@@ -41,6 +42,11 @@
my $PF_CONFIG = {};
my $OUTPUT_FILE = '/etc/network/interfaces';
my $GLOBAL_STRUCT = {};
+my @HEADER_DEST = (
+ "#################################################",
+ "# File was auto-generated with mk_interfaces tool",
+ "#\n",
+);
my $program = $0;
$program =~ s%.*/%%; # cheap basename
@@ -116,16 +122,20 @@
Abort( $CODE->{'EXEC'},
"An error occured during building interfaces file " . $OUTPUT_FILE );
}
-unless ( open( IFACE, ">" . $OUTPUT_FILE ) ) {
- die "Unable to open interface file " . $OUTPUT_FILE . "\n";
+
+my $output_fh = IO::File->new( '>' . $OUTPUT_FILE )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to open destination $OUTPUT_FILE : $OS_ERROR" );
+$output_fh->print( join "\n", @HEADER_DEST )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+foreach my $if ( @{ $iface->{'__order'} } ) {
+ $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
}
-print IFACE "#################################################\n";
-print IFACE "# File was auto-generated with mk_interfaces tool\n";
-print IFACE "#\n\n";
-foreach my $if ( @{ $iface->{'__order'} } ) {
- print IFACE join( "\n", @{ $iface->{$if} } );
- print IFACE "\n\n";
-}
-close(IFACE);
+$output_fh->close()
+ or Abort( $CODE->{'OPEN'},
+ "Unable to close destination file $OUTPUT_FILE : $OS_ERROR" );
exit 0;
Modified: branches/next-gen/sbin/mk_sitezone
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/sbin/mk_sitezone?rev=900&op=diff
==============================================================================
--- branches/next-gen/sbin/mk_sitezone (original)
+++ branches/next-gen/sbin/mk_sitezone Wed Sep 8 13:02:52 2010
@@ -24,6 +24,7 @@
use English qw( -no_match_vars ); # Avoids regex performance penalty
use Getopt::Long qw( :config ignore_case_always bundling );
+use IO::File;
use PFTools::Logger;
use PFTools::Utils;
@@ -98,10 +99,15 @@
= Mk_zone_for_site(
$GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$SITE}->{'zone'},
$SITE, $GLOBAL_STRUCT );
-unless ( open( ZONE, ">" . $OUTPUT_FILE ) ) {
- Abort( $CODE->{'OPEN'}, "Unable to open zone file " . $OUTPUT_FILE );
-}
-print ZONE join( "\n", @{$zone} );
-close(ZONE);
+
+my $output_fh = IO::File->new ( '>' . $OUTPUT_FILE )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to open destination file $OUTPUT_FILE : $OS_ERROR" );
+$output_fh->print( join "\n", @{$zone} )
+ or Abort( $CODE->{'OPEN'},
+ "Unable to write on destination file $OUTPUT_FILE : $OS_ERROR" );
+$output_fh->close()
+ or Abort( $CODE->{'OPEN'},
+ "Unable to close destination file $OUTPUT_FILE : $OS_ERROR" );
exit 0;
More information about the pf-tools-commits
mailing list