diff --git a/fhem/CHANGED b/fhem/CHANGED index d66d7d203..f4b3465df 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - fhem.pl: restoreDir restructured (Forum #85801) - added: 88_xs1Bridge: added blacklist function - feature: 93_DbLog: V3.9.0, syntax of attribute excludeDevs enhanced - update: 39_Talk2Fhem: Timephrases added, bugfixes and some changes diff --git a/fhem/FHEM/98_restore.pm b/fhem/FHEM/98_restore.pm index 25d570f83..0959fd6f9 100644 --- a/fhem/FHEM/98_restore.pm +++ b/fhem/FHEM/98_restore.pm @@ -27,15 +27,20 @@ CommandRestore($$) { my ($cl,$param) = @_; my @args = split(/ +/,$param); - my $list = (@args > 0 && $args[0] eq "list"); - shift @args if($list); - my $all = (@args > 0 && $args[0] eq "-a"); - shift @args if($all); - my $filename = shift @args; + + my $list; + $list = shift(@args) if(@args > 0 && $args[0] eq "list"); + + my $all; + $all = shift @args if(@args > 0 && $args[0] eq "-a"); + + my $filename; + $filename = shift @args if(@args > 0 && $args[0] !~ m/^-/); + my $dest = $attr{global}{modpath}; my $src = "$dest/restoreDir"; - $list = 1 if(!$list && !$filename); + $list = 1 if(!$list && (!$filename || $filename !~ m/20\d\d-\d\d-\d\d/)); return "Usage: restore [-a|list] filename|directory" if(@args); @@ -55,13 +60,11 @@ CommandRestore($$) return "$filename is not available for restore" if(!-e "$src/$filename"); - $filename .= "/" if($filename !~ m,/,); # needed for the regexp below - $filename =~ m,^([^/]*)/(.*)$,; $src = "$src/$filename"; - $dest = "$dest/$2" if($2); + $dest = "$dest/$1" if($filename =~ m,20\d\d-\d\d-\d\d/(.*)$,); - return (-f $src ? restoreFile($src,$dest,$all) : restoreDir($src,$dest,$all)). - "\n\nrestore finished"; + return (-f $src ? restoreFile($src,$dest,$all) : + restoreDir( $src,$dest,$all) ). "\n\nrestore finished"; } sub diff --git a/fhem/FHEM/98_update.pm b/fhem/FHEM/98_update.pm index f222eb7d6..558c0439a 100644 --- a/fhem/FHEM/98_update.pm +++ b/fhem/FHEM/98_update.pm @@ -271,7 +271,7 @@ doUpdate($$$$) ########################### # read in & digest the local control file my $root = $attr{global}{modpath}; - my $restoreDir = ($arg eq "check" ? "" : restoreDir_init()); + my $restoreDir = ($arg eq "check" ? "" : restoreDir_init("update")); my @locList; if(($arg eq "check" || $arg eq "all") && diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 2be9b9549..4b6f1f710 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -143,7 +143,7 @@ sub readingsDelete($$); sub redirectStdinStdErr(); sub rejectDuplicate($$$); sub resolveAttrRename($$); -sub restoreDir_init(); +sub restoreDir_init(;$); sub restoreDir_rmTree($); sub restoreDir_saveFile($$); sub restoreDir_mkDir($$$); @@ -1591,7 +1591,7 @@ CommandSave($$) return; } my $restoreDir; - $restoreDir = restoreDir_init() if(!configDBUsed()); + $restoreDir = restoreDir_init("save") if(!configDBUsed()); @structChangeHist = (); DoTrigger("global", "SAVE", 1); @@ -5404,8 +5404,9 @@ restoreDir_rmTree($) } sub -restoreDir_init() +restoreDir_init($) { + my ($subDir) = @_; my $root = $attr{global}{modpath}; my $nDirs = AttrVal("global","restoreDirs", 3); @@ -5416,6 +5417,7 @@ restoreDir_init() return "" if($nDirs == 0); my $rdName = "restoreDir"; + $rdName .= "/$subDir" if($subDir); my @t = localtime(gettimeofday()); my $restoreDir = sprintf("$rdName/%04d-%02d-%02d", $t[5]+1900, $t[4]+1, $t[3]); @@ -5426,7 +5428,7 @@ restoreDir_init() Log 1, "opendir $root/$rdName: $!"; return ""; } - my @oldDirs = sort grep { $_ !~ m/^\./ && $_ ne $restoreDir } readdir(DH); + my @oldDirs = sort grep { $_ =~ m/^20\d\d-\d\d-\d\d/ } readdir(DH); closedir(DH); while(int(@oldDirs) > $nDirs) { my $dir = "$root/$rdName/". shift(@oldDirs);