mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 04:04:03 -05:00
fix: stop zmrecover treating Deep scheme year directories as Shallow events refs #5904
This commit is contained in:
1 parent
a9e4d34935
commit
40638619de
2 files changed
+86
-1
No files matched your search
@@ -405,7 +405,8 @@ Debug("@Monitors");
|
||||
Error("Can't open directory '$$Storage{Path}/$monitor_dir': $!");
|
||||
next;
|
||||
}
|
||||
my @temp_events = sort { $b <=> $a } grep { -d $_ && $_ =~ /^\d+$/ } readdir( DIR );
|
||||
# A Deep scheme year directory is numeric too, but it holds date directories
|
||||
my @temp_events = sort { $b <=> $a } grep { /^(\d+)$/ && -d $_ && !(() = glob("$1/[0-9][0-9]")) } readdir( DIR );
|
||||
closedir(DIR);
|
||||
foreach my $event_id ( @temp_events ) {
|
||||
my $event = ZoneMinder::Event->find_one(Id=>$event_id);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Temp qw(tempdir);
|
||||
use File::Path qw(make_path);
|
||||
|
||||
my $failures = 0;
|
||||
my $passes = 0;
|
||||
|
||||
sub check {
|
||||
my ($name, $got, $want) = @_;
|
||||
if ($got eq $want) {
|
||||
$passes++;
|
||||
print "ok - $name\n";
|
||||
} else {
|
||||
$failures++;
|
||||
print "FAIL - $name\n got: $got\n want: $want\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub write_file {
|
||||
my ($path, $content) = @_;
|
||||
open(my $fh, '>', $path) or die "Can't write $path: $!";
|
||||
print $fh $content;
|
||||
close($fh);
|
||||
}
|
||||
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
make_path("$dir/lib/ZoneMinder", "$dir/run");
|
||||
# A Deep scheme event: the 26 year directory is numeric like a Shallow scheme event id
|
||||
make_path("$dir/storage/1/26/11/01/10/00/00");
|
||||
write_file("$dir/storage/1/26/11/01/10/00/00/5-video.mp4", '');
|
||||
|
||||
write_file("$dir/lib/ZoneMinder.pm", <<'EOM');
|
||||
package ZoneMinder;
|
||||
use ZoneMinder::Base;
|
||||
sub import {
|
||||
no strict 'refs';
|
||||
my $caller = caller();
|
||||
*{$caller.'::'.$_} = sub { 1 } for qw(logInit Debug Info Warning Error Fatal);
|
||||
*{$caller.'::zmDbConnect'} = sub { 1 };
|
||||
*{$caller.'::ZM_PID'} = sub () { '/nonexistent/zm.pid' };
|
||||
}
|
||||
1;
|
||||
EOM
|
||||
write_file("$dir/lib/DBI.pm", "package DBI;\n1;\n");
|
||||
write_file("$dir/lib/ZoneMinder/Base.pm", "package ZoneMinder::Base;\nuse constant ZM_VERSION => '0';\n1;\n");
|
||||
write_file("$dir/lib/ZoneMinder/Monitor.pm", <<'EOM');
|
||||
package ZoneMinder::Monitor;
|
||||
sub find { return bless({Id => 1}, 'ZoneMinder::Monitor'); }
|
||||
sub to_string { return 'monitor'; }
|
||||
1;
|
||||
EOM
|
||||
write_file("$dir/lib/ZoneMinder/Event.pm", <<'EOM');
|
||||
package ZoneMinder::Event;
|
||||
sub new { return bless({}, 'ZoneMinder::Event'); }
|
||||
sub find_one { return 0; }
|
||||
1;
|
||||
EOM
|
||||
write_file("$dir/lib/ZoneMinder/Storage.pm", <<EOM);
|
||||
package ZoneMinder::Storage;
|
||||
sub find { return bless({Id => 1, Path => '$dir/storage'}, 'ZoneMinder::Storage'); }
|
||||
sub Path { return \$_[0]{Path}; }
|
||||
1;
|
||||
EOM
|
||||
|
||||
my $source = do {
|
||||
open(my $fh, '<', "$FindBin::Bin/../../scripts/zmrecover.pl.in") or die "Can't open zmrecover.pl.in: $!";
|
||||
local $/;
|
||||
<$fh>;
|
||||
};
|
||||
$source =~ s/\@PERL_EXECUTABLE\@/$^X/g;
|
||||
$source =~ s/\@EXTRA_PERL_LIB\@//g;
|
||||
$source =~ s/\@ZM_RUNDIR\@/$dir\/run/g;
|
||||
$source =~ s/\@ZM_SCRIPT_PATH\@/\/usr\/bin:\/bin/g;
|
||||
write_file("$dir/zmrecover.pl", $source);
|
||||
|
||||
my $out = qx(printf "n\\nn\\nn\\n" | $^X -T -I$dir/lib $dir/zmrecover.pl 2>&1);
|
||||
my $prompts = () = $out =~ /resurrect/g;
|
||||
check('only the Deep event is offered for recovery', $prompts, 1);
|
||||
|
||||
print "\n$passes passed, $failures failed\n";
|
||||
exit($failures ? 1 : 0);
|
||||
Reference in new issue
Block a user