[Fai-commit] r2976 - in people/eartoast/features: .
fcopy-preinst/man fcopy-preinst/scripts
fai-repository at svn.debian.org
fai-repository at svn.debian.org
Mon Oct 31 19:26:12 UTC 2005
Author: glaweh-guest
Date: 2005-10-31 19:26:12 +0000 (Mon, 31 Oct 2005)
New Revision: 2976
Added:
people/eartoast/features/fcopy-preinst/
Modified:
people/eartoast/features/fcopy-preinst/man/fcopy.8
people/eartoast/features/fcopy-preinst/scripts/fcopy
Log:
preinst support; clean up ugly code
Copied: people/eartoast/features/fcopy-preinst (from rev 2974, trunk)
Modified: people/eartoast/features/fcopy-preinst/man/fcopy.8
===================================================================
--- trunk/man/fcopy.8 2005-10-27 22:26:05 UTC (rev 2974)
+++ people/eartoast/features/fcopy-preinst/man/fcopy.8 2005-10-31 19:26:12 UTC (rev 2976)
@@ -120,6 +120,20 @@
.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 is created
+.IP 2. 3
+preinst is called with the class being used and the full pathname to this
+temporary copy (you can do substitutions or other modifications)
+.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
Modified: people/eartoast/features/fcopy-preinst/scripts/fcopy
===================================================================
--- trunk/scripts/fcopy 2005-10-27 22:26:05 UTC (rev 2974)
+++ people/eartoast/features/fcopy-preinst/scripts/fcopy 2005-10-31 19:26:12 UTC (rev 2976)
@@ -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 {
More information about the Fai-commit
mailing list