mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 16:59:18 +00:00
Fix fhem.cfg corruption if some of the included files are not writeable
git-svn-id: https://svn.fhem.de/fhem/trunk@1559 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4cec234c09
commit
24e7e45be6
28
fhem/fhem.pl
28
fhem/fhem.pl
@ -1000,7 +1000,7 @@ CommandQuit($$)
|
|||||||
sub
|
sub
|
||||||
WriteStatefile()
|
WriteStatefile()
|
||||||
{
|
{
|
||||||
return if(!$attr{global}{statefile});
|
return "No statefile specified" if(!$attr{global}{statefile});
|
||||||
if(!open(SFH, ">$attr{global}{statefile}")) {
|
if(!open(SFH, ">$attr{global}{statefile}")) {
|
||||||
my $msg = "WriteStateFile: Cannot open $attr{global}{statefile}: $!";
|
my $msg = "WriteStateFile: Cannot open $attr{global}{statefile}: $!";
|
||||||
Log 1, $msg;
|
Log 1, $msg;
|
||||||
@ -1048,6 +1048,7 @@ WriteStatefile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(SFH);
|
close(SFH);
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@ -1055,7 +1056,9 @@ sub
|
|||||||
CommandSave($$)
|
CommandSave($$)
|
||||||
{
|
{
|
||||||
my ($cl, $param) = @_;
|
my ($cl, $param) = @_;
|
||||||
my $ret = WriteStatefile();
|
my $ret = "";
|
||||||
|
|
||||||
|
WriteStatefile();
|
||||||
|
|
||||||
$param = $attr{global}{configfile} if(!$param);
|
$param = $attr{global}{configfile} if(!$param);
|
||||||
return "No configfile attribute set and no argument specified" if(!$param);
|
return "No configfile attribute set and no argument specified" if(!$param);
|
||||||
@ -1063,6 +1066,7 @@ CommandSave($$)
|
|||||||
return "Cannot open $param: $!";
|
return "Cannot open $param: $!";
|
||||||
}
|
}
|
||||||
my %fh = ("configfile" => *SFH);
|
my %fh = ("configfile" => *SFH);
|
||||||
|
my %skip;
|
||||||
|
|
||||||
my %devByNr;
|
my %devByNr;
|
||||||
map { $devByNr{$defs{$_}{NR}} = $_ } keys %defs;
|
map { $devByNr{$defs{$_}{NR}} = $_ } keys %defs;
|
||||||
@ -1084,9 +1088,15 @@ CommandSave($$)
|
|||||||
my $cfgfile = $h->{CFGFN} ? $h->{CFGFN} : "configfile";
|
my $cfgfile = $h->{CFGFN} ? $h->{CFGFN} : "configfile";
|
||||||
my $fh = $fh{$cfgfile};
|
my $fh = $fh{$cfgfile};
|
||||||
if(!$fh) {
|
if(!$fh) {
|
||||||
return "Can't open $cfgfile: $!" if(!(open($fh, ">$cfgfile")));
|
if(!open($fh, ">$cfgfile")) {
|
||||||
$fh{$cfgfile} = $fh;
|
$ret .= "Cannot open $cfgfile: $!, ignoring its content\n";
|
||||||
|
$fh{$cfgfile} = 1;
|
||||||
|
$skip{$cfgfile} = 1;
|
||||||
|
} else {
|
||||||
|
$fh{$cfgfile} = $fh;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
next if($skip{$cfgfile});
|
||||||
|
|
||||||
if(!defined($d)) {
|
if(!defined($d)) {
|
||||||
print $fh $h->{TEXT},"\n";
|
print $fh $h->{TEXT},"\n";
|
||||||
@ -1114,9 +1124,9 @@ CommandSave($$)
|
|||||||
if($attr{global}{lastinclude});
|
if($attr{global}{lastinclude});
|
||||||
|
|
||||||
foreach my $fh (values %fh) {
|
foreach my $fh (values %fh) {
|
||||||
close($fh);
|
close($fh) if($fh ne "1");
|
||||||
}
|
}
|
||||||
return undef;
|
return ($ret ? $ret : undef);
|
||||||
}
|
}
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
@ -1754,7 +1764,7 @@ CommandAttr($$)
|
|||||||
|
|
||||||
my $list = getAllAttr($sdev);
|
my $list = getAllAttr($sdev);
|
||||||
if($a[1] eq "?") {
|
if($a[1] eq "?") {
|
||||||
push @rets, "Unknown attribute $a[1], choose one of $list";
|
push @rets, "$sdev: unknown attribute $a[1], choose one of $list";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1767,14 +1777,14 @@ CommandAttr($$)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$found) {
|
if(!$found) {
|
||||||
push @rets, "Unknown attribute $a[1], ".
|
push @rets, "$sdev: unknown attribute $a[1], ".
|
||||||
"choose one of $list or use attr global userattr $a[1]";
|
"choose one of $list or use attr global userattr $a[1]";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($a[1] eq "IODev" && (!$a[2] || !defined($defs{$a[2]}))) {
|
if($a[1] eq "IODev" && (!$a[2] || !defined($defs{$a[2]}))) {
|
||||||
push @rets,"Unknown IODev specified";
|
push @rets,"$sdev: unknown IODev specified";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user