From 07115422e70e6ae1ad3ca31ff38cd14ddea5d64d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 16 Feb 2023 09:39:54 -0500 Subject: [PATCH] Handle case where event has been moved but db not updated. This can happen when using a transaction and the db goes away. --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index c34c557c9..80c0b40b2 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -768,7 +768,17 @@ sub MoveTo { } my $OldStorage = $self->Storage(undef); - my $error = $self->CopyTo($NewStorage); + + # In strange situations where commits don't happen, the files can be moved but the db hasn't been updated. + # So here's a special case test to fix that. + my ( $SrcPath ) = ( $self->Path() =~ /^(.*)$/ ); # De-taint + my ( $NewPath ) = ( $NewStorage->Path() =~ /^(.*)$/ ); # De-taint + my $error = ''; + if (! -e $SrcPath and -e $NewPath) { + Warning("Event has already been moved, just updating the event."); + } else { + $error = $self->CopyTo($NewStorage); + } if (!$error) { # Succeeded in copying all files, so we may now update the Event. $$self{StorageId} = $$NewStorage{Id};