From b71581922fcd8a1f8e1dfeaafd0949a160d96690 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 17 Jan 2018 12:53:23 -0800 Subject: [PATCH 1/2] Only update db record if there is a change in diskspace --- scripts/zmfilter.pl.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/zmfilter.pl.in b/scripts/zmfilter.pl.in index 4db95e58b..40d519c3a 100644 --- a/scripts/zmfilter.pl.in +++ b/scripts/zmfilter.pl.in @@ -320,8 +320,10 @@ sub checkFilter { if ( $filter->{UpdateDiskSpace} ) { my $Event = new ZoneMinder::Event( $$event{Id}, $event ); - $Event->DiskSpace(undef); - $Event->save(); + my $old_diskspace = $$Event{DiskSpace}; + if ( $old_diskspace != $Event->DiskSpace(undef) ) { + $Event->save(); + } } # end if UpdateDiskSpace } # end foreach event } From eb92a1ed8ba867a4b6d77ddd25227967aab6c224 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 17 Jan 2018 12:59:34 -0800 Subject: [PATCH 2/2] merge updates that fix Event moving --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 48 +++++++++++++--------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index 134cfa794..1779317ff 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -367,11 +367,11 @@ sub delete_files { Error("No monitor id assigned to event $$event{Id}"); return; } - my $event_path = $event->Path(); - Debug("Deleting files for Event $$event{Id} from $event_path."); + my $event_path = $event->RelativePath(); + Debug("Deleting files for Event $$event{Id} from $storage_path/$event_path."); if ( $event_path ) { - ( $event_path ) = ( $event_path =~ /^(.*)$/ ); # De-taint - my $command = "/bin/rm -rf $event_path"; + #( $event_path ) = ( $event_path =~ /^(.*)$/ ); # De-taint + my $command = "/bin/rm -rf $storage_path/$event_path"; ZoneMinder::General::executeShellCommand( $command ); } @@ -380,7 +380,7 @@ sub delete_files { Debug("Deleting files for Event $$event{Id} from $storage_path/$link_path."); if ( $link_path ) { ( $link_path ) = ( $link_path =~ /^(.*)$/ ); # De-taint - unlink( $storage_path.'/'.$link_path ) or Error( "Unable to unlink '$storage_path/$link_path': $!" ); + unlink( $storage_path.'/'.$link_path ) or Error( "Unable to unlink '$storage_path/$link_path': $!" ); } } } # end sub delete_files @@ -395,11 +395,15 @@ sub Storage { sub check_for_in_filesystem { my $path = $_[0]->Path(); if ( $path ) { - my @files = glob( $path . '/*' ); -Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found " . scalar @files . " files"); - return 1 if @files; + if ( -e $path ) { + my @files = glob "$path/*"; + Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found " . scalar @files . " files"); + return 1 if @files; + } else { + Warning("Path not found for Event $_[0]{Id} at $path"); + } } -Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found no files"); + Debug("Checking for files for event $_[0]{Id} at $path using glob $path/* found no files"); return 0; } @@ -421,11 +425,15 @@ sub DiskSpace { $_[0]{DiskSpace} = $_[1]; } if ( ! defined $_[0]{DiskSpace} ) { - my $size = 0; - File::Find::find( { wanted=>sub { $size += -f $_ ? -s _ : 0 }, untaint=>1 }, $_[0]->Path() ); - $_[0]{DiskSpace} = $size; - Debug("DiskSpace for event $_[0]{Id} at $_[0]{Path} Updated to $size bytes"); - } + if ( -e $_[0]->Path() ) { + my $size = 0; + File::Find::find( { wanted=>sub { $size += -f $_ ? -s _ : 0 }, untaint=>1 }, $_[0]->Path() ); + $_[0]{DiskSpace} = $size; + Debug("DiskSpace for event $_[0]{Id} at $_[0]{Path} Updated to $size bytes"); + } else { + Warning("Event does not exist at $_[0]{Path}"); + } + } # end if ! defined DiskSpace } sub MoveTo { @@ -476,13 +484,13 @@ sub MoveTo { last; } } # end foreach file. + return $error if $error; - if ( ! $error ) { - # Succeeded in copying all files, so we may now update the Event. - $$self{StorageId} = $$NewStorage{Id}; - $$self{Storage} = $NewStorage; - $error .= $self->save(); - } + # Succeeded in copying all files, so we may now update the Event. + $$self{StorageId} = $$NewStorage{Id}; + $$self{Storage} = $NewStorage; + $error .= $self->save(); + return $error if $error; $self->delete_files( $OldStorage ); return $error; } # end sub MoveTo