anaconda.pm: use copy if newer for tftp files. greatly reduces the likelyhood of truncating files while they are being read with tftp. otherwise, this happens frequently when xcat is being controlled programmatically
Common.pm: add copy_if_newer utility function git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4660 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
dc010e96fa
commit
25138a3e6b
@ -4,6 +4,9 @@
|
||||
|
||||
package xCAT::Common;
|
||||
|
||||
use File::stat;
|
||||
use File::Copy;
|
||||
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
@ -130,4 +133,26 @@ sub usage_noderange {
|
||||
}
|
||||
}
|
||||
|
||||
# copy, overwriting only if the source file is newer
|
||||
sub copy_if_newer {
|
||||
my ($source, $dest) = @_;
|
||||
|
||||
die "ERROR: source file doesn't exist\n" unless (-e $source);
|
||||
|
||||
# resolve destination path
|
||||
if ($dest =~ m/\/$/ || -d $dest) {
|
||||
$dest .= '/' if ($dest !~ m/\/$/);
|
||||
$dest .= $1 if $source =~ m/([^\/]+)$/;
|
||||
}
|
||||
|
||||
if (-e $dest) {
|
||||
my $smtime = stat($source)->mtime;
|
||||
my $dmtime = stat($dest)->mtime;
|
||||
|
||||
return if ($smtime < $dmtime);
|
||||
}
|
||||
|
||||
copy($source, $dest);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -19,6 +19,8 @@ Getopt::Long::Configure("bundling");
|
||||
Getopt::Long::Configure("pass_through");
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
use xCAT::Common;
|
||||
|
||||
#use strict;
|
||||
my @cpiopid;
|
||||
|
||||
@ -292,18 +294,19 @@ sub mknetboot
|
||||
|
||||
mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
|
||||
#TODO: only copy if newer...
|
||||
unless ($donetftp{$osver,$arch,$profile}) {
|
||||
if (-f "$rootimgdir/hypervisor") {
|
||||
copy("$rootimgdir/hypervisor",
|
||||
"/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
$xenstyle=1;
|
||||
}
|
||||
copy("$rootimgdir/kernel",
|
||||
"/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
copy("$rootimgdir/initrd.gz",
|
||||
"/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
$donetftp{$osver,$arch,$profile} = 1;
|
||||
eval {
|
||||
if (-f "$rootimgdir/hypervisor") {
|
||||
xCAT::Common::copy_if_newer("$rootimgdir/hypervisor",
|
||||
"/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
$xenstyle=1;
|
||||
}
|
||||
xCAT::Common::copy_if_newer("$rootimgdir/kernel",
|
||||
"/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
xCAT::Common::copy_if_newer("$rootimgdir/initrd.gz",
|
||||
"/$tftpdir/xcat/netboot/$osver/$arch/$profile/");
|
||||
$donetftp{$osver,$arch,$profile} = 1;
|
||||
};
|
||||
}
|
||||
unless ( -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel"
|
||||
and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd.gz")
|
||||
@ -653,8 +656,21 @@ sub mkinstall
|
||||
unless ($doneimgs{"$os|$arch"})
|
||||
{
|
||||
mkpath("/tftpboot/xcat/$os/$arch");
|
||||
copy($kernpath,"$tftpdir/xcat/$os/$arch");
|
||||
copy($initrdpath,"$tftpdir/xcat/$os/$arch/initrd.img");
|
||||
eval {
|
||||
xCAT::Common::copy_if_newer($kernpath,"$tftpdir/xcat/$os/$arch");
|
||||
xCAT::Common::copy_if_newer($initrdpath,"$tftpdir/xcat/$os/$arch/initrd.img");
|
||||
};
|
||||
|
||||
if ($@) {
|
||||
$callback->(
|
||||
{
|
||||
error => ["copying pxe files failed: $@"],
|
||||
errorcode => [1],
|
||||
}
|
||||
);
|
||||
next;
|
||||
}
|
||||
|
||||
$doneimgs{"$os|$arch"} = 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user