[Fai-commit] r3043 - in trunk: . bin debian man

fai-repository at svn.debian.org fai-repository at svn.debian.org
Fri Nov 11 15:13:09 UTC 2005


Author: lange
Date: 2005-11-11 15:13:09 +0000 (Fri, 11 Nov 2005)
New Revision: 3043

Modified:
   trunk/NEWS
   trunk/bin/fcopy
   trunk/debian/changelog
   trunk/man/fcopy.8
Log:
merge  people/eartoast/bugfix/297550 and people/eartoast/features/fcopy-preinst


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2005-11-11 14:46:04 UTC (rev 3042)
+++ trunk/NEWS	2005-11-11 15:13:09 UTC (rev 3043)
@@ -4,6 +4,7 @@
       fai-server, fai-client, fai-nfsroot, fai-doc, fai-quickstart
     - Config scripts named S[0-9][0-9]* are not executed any
       more. Rename them to match [0-9][0-9]*.
+    - fcopy now supports a preinst script
 
 New in FAI 2.8.4
 

Modified: trunk/bin/fcopy
===================================================================
--- trunk/bin/fcopy	2005-11-11 14:46:04 UTC (rev 3042)
+++ trunk/bin/fcopy	2005-11-11 15:13:09 UTC (rev 3043)
@@ -6,7 +6,7 @@
 # fcopy -- copy files using FAI classes and preserve directory structure
 #
 # This script is part of FAI (Fully Automatic Installation)
-# Copyright (C) 2000-2004 Thomas Lange, lange at informatik.uni-koeln.de
+# Copyright (C) 2000-2005 Thomas Lange, lange at informatik.uni-koeln.de
 # Universitaet zu Koeln
 #
 #*********************************************************************
@@ -27,7 +27,7 @@
 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #*********************************************************************
 
-my $version = "Version 1.23, 24-march-2005";
+my $version = "Version 2.0, 11-nov-march-2005";
 
 use strict;
 use File::Copy;
@@ -35,6 +35,8 @@
 use File::Find;
 use File::Path;
 use File::Basename;
+use File::Spec;
+use File::Temp qw/tempfile/;
 use Getopt::Std;
 
 use vars qw/*name/;
@@ -78,6 +80,7 @@
   my $tpath = "$target/" . dirname $source;
   my $preserve = 0;
   my $logcomment = "";
+  my ($tmpfh,$tmpfile);
 
   warn "copy_one: source: $source: ps: $ps tpath: $tpath\n" if $debug;
 
@@ -93,15 +96,22 @@
   unless (defined $class) {
     ewarn("no matching file for any class for $source defined.");
     # do not copy
-    $opt_d and -f $destfile and ($nobackup and unlink($destfile) or 
-      (-d $bpath or mkpath($bpath,$debug,0755)) and move($destfile,$backupfile));
+    if ($opt_d and -f $destfile) {
+      print LOGFILE "$source\tNONE\t# removed (no matching class)\n" if $logfile;
+      if ($nobackup) {
+        unlink($destfile)
+      } else {
+        mkpath($bpath,$debug,0755) unless -d $bpath;
+	move($destfile,$backupfile) if -d $bpath;;
+      }
+    }
     return;
   }
   warn "using class: $class\n" if $debug;
-  $sourcefile = "$ps/$class";
+  $tmpfile = $sourcefile = "$ps/$class";
 
   # do nothing if source and destination files are equal 
-  if ($opt_update) {
+  if ($opt_update and not -x "$ps/preinst") {
     # compare logically
     if ($lastclass{$source}) {
       # $source has already been copied last time
@@ -123,8 +133,17 @@
     }
   } else {
     # compare literally
+    if ( -x "$ps/preinst" ) {
+      warn "preinst script found, switching to literal change detection" if
+        ($opt_P and $debug);
+      ($tmpfh,$tmpfile)=tempfile("fcopy.XXXXXX",DIR=>File::Spec->tmpdir());
+      warn "preinst script found, copying $sourcefile to $tmpfile" if $debug;
+      ewarn("copying $sourcefile for preinst processing failed !") unless
+        copy($sourcefile,$tmpfh);
+      runscript("preinst",$ps,$tmpfile,$class);
+    };
 
-    if ( compare($sourcefile,$destfile)) {
+    if ( compare($tmpfile,$destfile)) {
       $logcomment="\t# new (literal)";
     } else {
       $logcomment="\t# preserved (literal)" if $logfile;
@@ -157,21 +176,21 @@
   # what should I do if $destfile is a symlink?
   $nobackup or (-f $destfile and 
     (-d $bpath or mkpath($bpath,$debug,0755)) and move($destfile,$backupfile));
-  if (copy($sourcefile,$destfile)) {
+  if (copy($tmpfile,$destfile)) {
     print "fcopy: copied $sourcefile to $destfile\n" ;
-    postinst($ps,$destfile,$class);
+    runscript("postinst",$ps,$destfile,$class);
     set_mode($ps,$destfile,$class);
   } else {
     ewarn("copy $sourcefile to $destfile failed. $!") ;
   }
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-sub postinst {
+sub runscript {
 
-  my ($sourcefile,$destfile,$class) = @_;
-  return unless -x "$sourcefile/postinst"; 
-  warn "executing $sourcefile/postinst $class $destfile\n" if $debug;
-  system "$sourcefile/postinst $class $destfile";
+  my ($scriptname,$sourcefile,$destfile,$class) = @_;
+  return unless -x "$sourcefile/$scriptname"; 
+  warn "executing $sourcefile/$scriptname $class $destfile\n" if $debug;
+  system "$sourcefile/$scriptname $class $destfile";
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 sub name2num {
@@ -342,20 +361,6 @@
   exit 0;
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-sub rfilter {
-
-  # Filter for recursive copying
-  
-  # are we in a directory ? should we ignore it ?
-  my $location=$_;
-  (-d and (! grep $location eq $_, at ignoredirs )) or return 0;
-  # a directory without subdirs has two hard links
-  # don't count @ignoredirs as subdirs
-  my $subdirs=(lstat($_))[3] - 2 - grep(-d, at ignoredirs);
-  # push leaf
-  push @rlist,$File::Find::name unless $subdirs;
-}
-# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 # main program
 
 $|=1;
@@ -396,8 +401,20 @@
 
 if ($opt_r) {
   foreach (@ARGV) { $_="$source/$_"; } # add prefix to list of directories
-  File::Find::find(\&rfilter, at ARGV);
-  foreach (@rlist) { $_=~ s#^$source/##; }   # remove prefix from all fines found
+  my %has_subdirs;
+  my %ignoredirs;
+  map $ignoredirs{$_}=1, at ignoredirs;
+  File::Find::find({
+    wanted=>sub{ $has_subdirs{$File::Find::dir} |= -d},
+    preprocess=>sub{grep ! (-d and exists($ignoredirs{$_})), at _}},
+    @ARGV);
+  foreach (keys %has_subdirs) {
+    unless ($has_subdirs{$_}) {
+      # remove prefix from all files found
+      s#^$source/##;
+      push @rlist,$_;
+    }
+  }
   warn "List of all files found by File::Find::find: @rlist" if $debug;
   @ARGV = @rlist;
 }

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2005-11-11 14:46:04 UTC (rev 3042)
+++ trunk/debian/changelog	2005-11-11 15:13:09 UTC (rev 3043)
@@ -16,6 +16,7 @@
     (closes: #312128) 
   * fai-mirror: add -i to egrep (closes: #312508)
   * fai-do-scripts: do not execute S[0-9][0-9]* any more (closes: #310999)
+  * fcopy: add preinst supprt, fix for inforing .svn dirs (closes: #297550)
   
  -- Thomas Lange <lange at debian.org>  Fri, 11 Nov 2005 15:45:15 +0100
 

Modified: trunk/man/fcopy.8
===================================================================
--- trunk/man/fcopy.8	2005-11-11 14:46:04 UTC (rev 3042)
+++ trunk/man/fcopy.8	2005-11-11 15:13:09 UTC (rev 3043)
@@ -120,6 +120,21 @@
 
 .SH SCRIPTS
 .TP
+.B preinst
+If a file 'preinst' exists and is executable, it is used in the following way:
+.RS
+.IP 1. 3
+a temporary copy of the file for the used class is created
+.IP 2. 3
+preinst is called with the used class and the full pathname to this 
+temporary copy (you can do in-place substitutions or other modifications on this
+copy)
+.IP 3. 3
+the copy is compared to the destination and replaces it only if there are 
+any differences
+.RE
+
+.TP
 .B postinst
 If a file 'postinst' exists and is executable, it is called after
 successfully having copied the file with the class being used and the full




More information about the Fai-commit mailing list