From 1e52934dcf62ab14cb02797759b2ccf1e72658d2 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 20 May 2016 20:33:47 -0400 Subject: [PATCH] Implement a time function that gets unix_timestamp from StartTime, and implement check_for_files_in_filessytem --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 24 ++++++++++++++++++++-- scripts/zmaudit.pl.in | 8 ++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index a750c062b..a7b74afb3 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -45,6 +45,7 @@ use parent qw(ZoneMinder::Object); use ZoneMinder::Config qw(:all); use ZoneMinder::Logger qw(:all); use ZoneMinder::Database qw(:all); +require Date::Parse; use vars qw/ $table $primary_key /; $table = 'Events'; @@ -52,6 +53,17 @@ $primary_key = 'Id'; use POSIX; +sub Time { + if ( @_ > 1 ) { + $_[0]{Time} = $_[1]; + } + if ( ! defined $_[0]{Time} ) { + + $_[0]{Time} = Date::Parse::str2time( $_[0]{StartTime} ); + } + return $_[0]{Time}; +} + sub Name { if ( @_ > 1 ) { $_[0]{Name} = $_[1]; @@ -96,9 +108,12 @@ sub find_one { } sub getPath { +return Path( @_ ); +} +sub Path { my $event = shift; - my $Storage = $event->Storage(); + my $Storage = $event->Storage(); my $event_path = ""; if ( $Config{ZM_USE_DEEP_STORAGE} ) { @@ -106,7 +121,7 @@ sub getPath { $Storage->Path(), $event->{MonitorId}, strftime( "%y/%m/%d/%H/%M/%S", - localtime($event->{Time}) + localtime($event->Time()) ), ); } else { @@ -305,6 +320,11 @@ sub delete_files { sub Storage { return new ZoneMinder::Storage( $_[0]{StorageId} ); } +sub check_for_in_filesystem { + my $path = $_[0]->Path(); + my @files = glob( $path . '/*' ); + return 1 if @files; +} 1; __END__ diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index fa4cd1b76..0cc47c815 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -350,8 +350,12 @@ MAIN: while( $loop ) { while ( my ( $db_event, $age ) = each(%$db_events ) ) { if ( !defined($fs_events->{$db_event}) ) { +my $Event = new ZoneMinder::Event( $db_event ); +if ( $Event->check_for_in_filesystem() ) { +Debug("Database events apparent exists at " . $Event->Path() ); +} else { if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) { - aud_print( "Database event '$db_monitor/$db_event' does not exist in filesystem" ); + aud_print( "Database event '$db_monitor/$db_event' does not exist at " . $Event->Path()." in filesystem" ); if ( confirm() ) { my $res = $deleteEventSth->execute( $db_event ) or Fatal( "Can't execute: ".$deleteEventSth->errstr() ); @@ -362,11 +366,11 @@ MAIN: while( $loop ) { $cleaned = 1; } } else { - my $Event = new ZoneMinder::Event( $db_event ); my $Storage = $Event->Storage(); aud_print( "Database event '".$Event->getPath()."/$db_monitor/$db_event' does not exist in filesystem but too young to delete.\n" ); } + } } } }