pf-tools commit: r821 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Update.pm lib/PFTools/Update/Addfile.pm lib/PFTools/Update/Common.pm lib/PFTools/Update/File.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Aug 12 21:21:25 UTC 2010
Author: ccaillet-guest
Date: Thu Aug 12 21:21:19 2010
New Revision: 821
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=821
Log:
* lib/PFTools/Update/Addfile.pm
- extrating addfile functions (action and depends) from Update.pm
Added:
branches/next-gen/lib/PFTools/Update/Addfile.pm
- copied, changed from r820, branches/next-gen/lib/PFTools/Update/File.pm
Removed:
branches/next-gen/lib/PFTools/Update/File.pm
Modified:
branches/next-gen/debian/changelog
branches/next-gen/lib/PFTools/Update.pm
branches/next-gen/lib/PFTools/Update/Common.pm
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=821&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Aug 12 21:21:19 2010
@@ -15,8 +15,10 @@
* lib/PFTools/Update/Common.pm
- extracting common functions from Update.pm which are used by $FUNCTION
and $DEPENDS in lib/PFTools/Update.pm
-
- -- Christophe Caillet <quadchris at free.fr> Sat, 07 Aug 2010 11:44:03 +0200
+ * lib/PFTools/Update/Addfile.pm
+ - extrating addfile functions (action and depends) from Update.pm
+
+ -- Christophe Caillet <quadchris at free.fr> Thu, 12 Aug 2010 23:19:31 +0200
pf-tools (0.99.98-1) unstable; urgency=low
Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=821&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Thu Aug 12 21:21:19 2010
@@ -78,99 +78,99 @@
my %DEPENDS;
my %FUNCTIONS;
-$DEPENDS{'addfile'} = sub ($$$) {
- my ( $ref_section, $dest, $options ) = @_;
-
- while ( $dest ne "/" && $dest ne "." ) {
- $ref_section->{'depends'} .= " " . dirname($dest);
- $dest = dirname($dest);
- }
-};
-
-$FUNCTIONS{'addfile'} = sub ($$$$$) {
- my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
- my ( $source, $tmp, $cmp );
-
- my $diff = 0;
- $hash_subst->{'SECTIONNAME'} = $dest;
- if ( $ref_section->{'source'} =~ /\s/ ) {
- $source = Get_tmp_dest ($dest).".merged";
- unlink ($source);
- my $splitsource;
- foreach $splitsource ( split( ' ', $ref_section->{'source'} ) ) {
- $splitsource = Get_source( Subst_vars ( $splitsource, $hash_subst ) );
- if ( ! -f $splitsource ) {
- Warn( $CODE->{'OPEN'}, "Unable to open ".$splitsource );
- return 1;
- }
- if ( deferredlogsystem( "cat '".$splitsource."' >> ".$source ) ) {
- Warn( $CODE->{'EXEC'},
- "Unable to append file ".$splitsource." to ".$tmp );
- return 1;
- }
- }
- }
- else {
- $source = Get_source( Subst_vars( $ref_section->{'source'}, $hash_subst ), $hash_subst );
- }
-
- $hash_subst->{'SOURCE'} = $source;
- $tmp = Get_tmp_dest($dest);
- $hash_subst->{'DESTINATION'} = $tmp;
- if ( defined( $ref_section->{'filter'} ) ) {
- my $filter = Subst_vars( $ref_section->{'filter'}, $hash_subst );
- if ( deferredlogsystem ($filter) ) {
- Warn( $CODE->{'OPEN'}, "Unable to apply filter " . $filter );
- return 1;
- }
- }
- else {
- if ( ! copy ( $source, $tmp ) ) {
- Warn( $CODE->{'COPY'},
- "Unable to copy ".$source." to ".$tmp );
- return 1;
- }
- }
-
- if ( ! -f $tmp ) {
- Warn( $CODE->{'OPEN'}, "Unable to open " . $tmp );
- return 1;
- }
- elsif ( compare ( $tmp, $dest ) ) {
- $diff = 1;
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log("(action needed)");
- }
- if ( $options->{'diff'} ) {
- deferredlogsystem( "/usr/bin/diff -uN '".$dest."' '".$tmp."'" );
- }
- Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
- Do_before_change ( $ref_section, $options, $hash_subst ) && return 1;
- if ( !$options->{'simul'} ) {
- # Fuck dpkg conffiles
- if ( $options->{'noaction'}
- && -e $dest
- && ! -e $dest.'.dpkg-dist'
- ) {
- copy ( $dest, $dest.'.dpkg-dist' );
- Do_moveold( $dest, $options );
- if ( Mk_dest_dir($dest)
- || ! copy ( $tmp, $dest )
- ) {
- Warn( $CODE->{'OPEN'},
- "Unable to copy file " . $tmp . " to " . $dest );
- return 1;
- }
- }
- }
- }
- Do_chownmod( $ref_section, $dest, $options );
- if ( $diff ) {
- Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
- Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
- }
- return 0;
-};
+# $DEPENDS{'addfile'} = sub ($$$) {
+# my ( $ref_section, $dest, $options ) = @_;
+#
+# while ( $dest ne "/" && $dest ne "." ) {
+# $ref_section->{'depends'} .= " " . dirname($dest);
+# $dest = dirname($dest);
+# }
+# };
+#
+# $FUNCTIONS{'addfile'} = sub ($$$$$) {
+# my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+# my ( $source, $tmp, $cmp );
+#
+# my $diff = 0;
+# $hash_subst->{'SECTIONNAME'} = $dest;
+# if ( $ref_section->{'source'} =~ /\s/ ) {
+# $source = Get_tmp_dest ($dest).".merged";
+# unlink ($source);
+# my $splitsource;
+# foreach $splitsource ( split( ' ', $ref_section->{'source'} ) ) {
+# $splitsource = Get_source( Subst_vars ( $splitsource, $hash_subst ) );
+# if ( ! -f $splitsource ) {
+# Warn( $CODE->{'OPEN'}, "Unable to open ".$splitsource );
+# return 1;
+# }
+# if ( deferredlogsystem( "cat '".$splitsource."' >> ".$source ) ) {
+# Warn( $CODE->{'EXEC'},
+# "Unable to append file ".$splitsource." to ".$tmp );
+# return 1;
+# }
+# }
+# }
+# else {
+# $source = Get_source( Subst_vars( $ref_section->{'source'}, $hash_subst ), $hash_subst );
+# }
+#
+# $hash_subst->{'SOURCE'} = $source;
+# $tmp = Get_tmp_dest($dest);
+# $hash_subst->{'DESTINATION'} = $tmp;
+# if ( defined( $ref_section->{'filter'} ) ) {
+# my $filter = Subst_vars( $ref_section->{'filter'}, $hash_subst );
+# if ( deferredlogsystem ($filter) ) {
+# Warn( $CODE->{'OPEN'}, "Unable to apply filter " . $filter );
+# return 1;
+# }
+# }
+# else {
+# if ( ! copy ( $source, $tmp ) ) {
+# Warn( $CODE->{'COPY'},
+# "Unable to copy ".$source." to ".$tmp );
+# return 1;
+# }
+# }
+#
+# if ( ! -f $tmp ) {
+# Warn( $CODE->{'OPEN'}, "Unable to open " . $tmp );
+# return 1;
+# }
+# elsif ( compare ( $tmp, $dest ) ) {
+# $diff = 1;
+# if ( $options->{'verbose'} || $options->{'simul'} ) {
+# Log("(action needed)");
+# }
+# if ( $options->{'diff'} ) {
+# deferredlogsystem( "/usr/bin/diff -uN '".$dest."' '".$tmp."'" );
+# }
+# Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+# Do_before_change ( $ref_section, $options, $hash_subst ) && return 1;
+# if ( !$options->{'simul'} ) {
+# # Fuck dpkg conffiles
+# if ( $options->{'noaction'}
+# && -e $dest
+# && ! -e $dest.'.dpkg-dist'
+# ) {
+# copy ( $dest, $dest.'.dpkg-dist' );
+# Do_moveold( $dest, $options );
+# if ( Mk_dest_dir($dest)
+# || ! copy ( $tmp, $dest )
+# ) {
+# Warn( $CODE->{'OPEN'},
+# "Unable to copy file " . $tmp . " to " . $dest );
+# return 1;
+# }
+# }
+# }
+# }
+# Do_chownmod( $ref_section, $dest, $options );
+# if ( $diff ) {
+# Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+# Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+# }
+# return 0;
+# };
$FUNCTIONS{'dpkg-purge'} = sub ($$$$$) {
my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
@@ -808,40 +808,43 @@
return 0;
};
-sub Mk_dest_dir ($) {
- my ( $dir ) = @_;
-
- $dir =~ s://:/:g; # supprimer // sinon ca marche moins bien
- $dir =~ s:/[^/]+/*$::;
- my $dir2 = $dir;
- while ( $dir2 ne "" && !-e $dir2 ) {
- $dir2 =~ s:/[^/]+/*$::;
- }
- if ( $dir2 ne "" && -e $dir2 && !-d $dir2 ) {
- unlink($dir2);
- }
- $dir && return system( "/bin/mkdir -p '" . $dir . "' >/dev/null 2>&1" );
-}
-
-sub Get_tmp_dest ($) {
- my ( $dest ) = @_;
-
- my $pf_config = Init_PF_CONFIG ();
- my $tmp = $pf_config->{'path'}->{'checkout_dir'} . "/tmp/" . $dest;
- Mk_dest_dir ( $tmp );
- if ( -d $tmp ) {
- rmdir( $tmp );
- }
- elsif ( -e $tmp ) {
- unlink ( $tmp );
- }
- return $tmp;
-}
+# sub Mk_dest_dir ($) {
+# my ( $dir ) = @_;
+#
+# $dir =~ s://:/:g; # supprimer // sinon ca marche moins bien
+# $dir =~ s:/[^/]+/*$::;
+# my $dir2 = $dir;
+# while ( $dir2 ne "" && !-e $dir2 ) {
+# $dir2 =~ s:/[^/]+/*$::;
+# }
+# if ( $dir2 ne "" && -e $dir2 && !-d $dir2 ) {
+# unlink($dir2);
+# }
+# $dir && return system( "/bin/mkdir -p '" . $dir . "' >/dev/null 2>&1" );
+# }
+#
+# sub Get_tmp_dest ($) {
+# my ( $dest ) = @_;
+#
+# my $pf_config = Init_PF_CONFIG ();
+# my $tmp = $pf_config->{'path'}->{'checkout_dir'} . "/tmp/" . $dest;
+# Mk_dest_dir ( $tmp );
+# if ( -d $tmp ) {
+# rmdir( $tmp );
+# }
+# elsif ( -e $tmp ) {
+# unlink ( $tmp );
+# }
+# return $tmp;
+# }
sub Get_depends_for_action ($$$$) {
my ( $action, $ref_section, $dest, $options ) = @_;
- if ( $DEPENDS{$action} ) {
+ if ( $action eq 'addfile' ) {
+ Addfile_depends ( $ref_section, $dest, $options );
+ }
+ elsif ( $DEPENDS{$action} ) {
$DEPENDS{$action}->( $ref_section, $dest, $options );
}
}
@@ -849,6 +852,7 @@
sub Exec_action ($$$$$$) {
my ( $action, $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+ return Addfile_action ( $ref_section, $dest, $options, $hash_subst, $global_config ) if ( $action eq 'addfile' );
return $FUNCTIONS{$action}->( $ref_section, $dest, $options, $hash_subst, $global_config );
}
Copied: branches/next-gen/lib/PFTools/Update/Addfile.pm (from r820, branches/next-gen/lib/PFTools/Update/File.pm)
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Addfile.pm?rev=821&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update/File.pm (original)
+++ branches/next-gen/lib/PFTools/Update/Addfile.pm Thu Aug 12 21:21:19 2010
@@ -27,18 +27,112 @@
our @ISA = ('Exporter');
our @EXPORT = qw(
- Get_depends_for_action
- Exec_action
- Trie_dependances
- dirname
+ Addfile_depends
+ Addfile_action
);
our @EXPORT_OK = qw();
use File::Compare;
use File::Copy;
+use Text::Diff;
use PFTools::Logger;
-use PFTools::Parser;
-use PFTools::Net;
-use PFTools::Host;
+use PFTools::Conf;
+use PFTools::Update::Common;
+sub Addfile_depends ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ while ( $dest ne "/" && $dest ne "." ) {
+ $ref_section->{'depends'} .= " " . dirname($dest);
+ $dest = dirname($dest);
+ }
+}
+
+sub Addfile_action ($$$$$) {
+ my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+ my ( $source, $tmp, $cmp );
+
+ my $diff = 0;
+ $hash_subst->{'SECTIONNAME'} = $dest;
+ if ( $ref_section->{'source'} =~ /\s/ ) {
+ $source = Get_tmp_dest ($dest).".merged";
+ unlink ($source);
+ my $splitsource;
+ foreach $splitsource ( split( ' ', $ref_section->{'source'} ) ) {
+ $splitsource = Get_source( Subst_vars ( $splitsource, $hash_subst ), $options->{'host'}, $hash_subst );
+ if ( ! -f $splitsource ) {
+ Warn( $CODE->{'OPEN'}, "Unable to open ".$splitsource );
+ return 1;
+ }
+ if ( deferredlogsystem( "cat '".$splitsource."' >> ".$source ) ) {
+ Warn( $CODE->{'EXEC'},
+ "Unable to append file ".$splitsource." to ".$tmp );
+ return 1;
+ }
+ }
+ }
+ else {
+ $source = Get_source( Subst_vars( $ref_section->{'source'}, $hash_subst ), $hash_subst );
+ }
+
+ $hash_subst->{'SOURCE'} = $source;
+ $tmp = Get_tmp_dest($dest);
+ $hash_subst->{'DESTINATION'} = $tmp;
+ if ( defined( $ref_section->{'filter'} ) ) {
+ my $filter = Subst_vars( $ref_section->{'filter'}, $hash_subst );
+ if ( deferredlogsystem ($filter) ) {
+ Warn( $CODE->{'OPEN'}, "Unable to apply filter " . $filter );
+ return 1;
+ }
+ }
+ else {
+ if ( ! copy ( $source, $tmp ) ) {
+ Warn( $CODE->{'COPY'},
+ "Unable to copy ".$source." to ".$tmp );
+ return 1;
+ }
+ }
+
+ if ( ! -f $tmp ) {
+ Warn( $CODE->{'OPEN'}, "Unable to open " . $tmp );
+ return 1;
+ }
+ elsif ( compare ( $tmp, $dest ) ) {
+ $diff = 1;
+ if ( $options->{'verbose'} || $options->{'simul'} ) {
+ Log("(action needed)");
+ }
+ if ( $options->{'diff'} ) {
+ print diff ( $dest, $tmp, { STYLE => "Unified" } );
+# deferredlogsystem( "/usr/bin/diff -uN '".$dest."' '".$tmp."'" );
+ }
+ Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+ Do_before_change ( $ref_section, $options, $hash_subst ) && return 1;
+ if ( !$options->{'simul'} ) {
+ # Fuck dpkg conffiles
+ if ( $options->{'noaction'}
+ && -e $dest
+ && ! -e $dest.'.dpkg-dist'
+ ) {
+ copy ( $dest, $dest.'.dpkg-dist' );
+ Do_moveold( $dest, $options );
+ if ( Mk_dest_dir($dest)
+ || ! copy ( $tmp, $dest )
+ ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to copy file " . $tmp . " to " . $dest );
+ return 1;
+ }
+ }
+ }
+ }
+ Do_chownmod( $ref_section, $dest, $options );
+ if ( $diff ) {
+ Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+ Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+ }
+ return 0;
+};
+
+1;
Modified: branches/next-gen/lib/PFTools/Update/Common.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Common.pm?rev=821&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Common.pm (original)
+++ branches/next-gen/lib/PFTools/Update/Common.pm Thu Aug 12 21:21:19 2010
@@ -34,7 +34,9 @@
Do_chownmod
Do_moveold
Exec_cmd
- dirname
+ Mk_dest_dir
+ Get_tmp_dest
+ dirname
isipaddr
ln_sfn
);
@@ -235,4 +237,35 @@
}
}
+sub Mk_dest_dir ($) {
+ my ( $dir ) = @_;
+
+ $dir =~ s://:/:g; # supprimer // sinon ca marche moins bien
+ $dir =~ s:/[^/]+/*$::;
+ my $dir2 = $dir;
+ while ( $dir2 ne "" && !-e $dir2 ) {
+ $dir2 =~ s:/[^/]+/*$::;
+ }
+ if ( $dir2 ne "" && -e $dir2 && !-d $dir2 ) {
+ unlink($dir2);
+ }
+ $dir && return system( "/bin/mkdir -p '" . $dir . "' >/dev/null 2>&1" );
+}
+
+sub Get_tmp_dest ($) {
+ my ( $dest ) = @_;
+
+ my $pf_config = Init_PF_CONFIG ();
+ my $tmp = $pf_config->{'path'}->{'checkout_dir'} . "/tmp/" . $dest;
+ Mk_dest_dir ( $tmp );
+ if ( -d $tmp ) {
+ rmdir( $tmp );
+ }
+ elsif ( -e $tmp ) {
+ unlink ( $tmp );
+ }
+ return $tmp;
+}
+
+
1;
More information about the pf-tools-commits
mailing list