2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

98_update.pm: change from mv to copy for some operations (Forum #35603)

git-svn-id: https://svn.fhem.de/fhem/trunk@8329 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2015-03-29 15:40:33 +00:00
parent 45ceab5d88
commit 765836fc48

View File

@ -5,7 +5,7 @@ package main;
use strict;
use warnings;
use HttpUtils;
use File::Copy qw(mv);
use File::Copy qw(mv cp);
use Blocking;
sub CommandUpdate($$);
@ -14,6 +14,7 @@ sub upd_initRestoreDirs($);
sub upd_mkDir($$$);
sub upd_rmTree($);
sub upd_writeFile($$$$);
sub upd_mv($$);
my $updateInBackground;
my $updRet;
@ -174,7 +175,7 @@ doUpdate($$)
return 1;
}
upd_mkDir($root, $r[2], 0);
my $mvret = mv "$root/$r[1]", "$root/$r[2]";
my $mvret = upd_mv("$root/$r[1]", "$root/$r[2]");
uLog 4, "mv $root/$r[1] $root/$r[2]". ($mvret ? " FAILED:$mvret":"");
}
@ -272,6 +273,30 @@ doUpdate($$)
}
}
sub
upd_mv($$)
{
my ($src, $dest) = @_;
if($src =~ m/\*/) {
$src =~ m,^(.*)/([^/]+)$,;
my ($dir, $pat) = ($1, $2);
$pat = "^$pat\$";
opendir(my $dh, $dir) || return "$dir: $!";
while(my $r = readdir($dh)) {
next if($r !~ m/$pat/ || "$dir/$r" eq $dest);
my $mvret = mv("$dir/$r", $dest);
return "MV $dir/$r $dest: $!" if(!$mvret);
Log 3, "MV $dir/$r $dest";
}
closedir($dh);
} else {
return "MV $src $dest: $!" if(mv($src, $dest));
}
return undef;
}
sub
upd_mkDir($$$)
{
@ -347,8 +372,8 @@ upd_writeFile($$$$)
upd_mkDir($root, $fName, 1);
upd_mkDir($root, "$restoreDir/$fName", 1) if($restoreDir);
if($restoreDir && -f "$root/$fName" &&
! mv("$root/$fName", "$root/$restoreDir/$fName")) {
uLog 1, "mv $root/$fName $root/$restoreDir/$fName failed:$!, ".
! cp("$root/$fName", "$root/$restoreDir/$fName")) {
uLog 1, "cp $root/$fName $root/$restoreDir/$fName failed:$!, ".
"aborting the update";
return 0;
}
@ -359,7 +384,7 @@ upd_writeFile($$$$)
$fPath = $0 if($fPath =~ m/$mainPgm/);
if(!open(FD, ">$fPath")) {
uLog 1, "open $fPath failed: $!, $rest";
mv "$root/$restoreDir/$fName", "$root/$fName" if($restoreDir);
cp "$root/$restoreDir/$fName", "$root/$fName" if($restoreDir);
return 0;
}
binmode(FD);
@ -369,7 +394,7 @@ upd_writeFile($$$$)
my $written = -s "$fPath";
if($written != length($content)) {
uLog 1, "writing $fPath failed: $!, $rest";
mv "$root/$restoreDir/$fName", "$fPath" if($restoreDir);
cp "$root/$restoreDir/$fName", "$fPath" if($restoreDir);
return;
}