Merge branch 'master' into storageareas

This commit is contained in:
Isaac Connor 2018-09-09 14:09:52 -04:00
commit 5eec7e00c5
10 changed files with 66 additions and 57 deletions

View File

@ -69,7 +69,7 @@ sub find {
push @sql_values, $sql_filters{Name}; push @sql_values, $sql_filters{Name};
} }
if ( exists $sql_filters{ServerId} ) { if ( exists $sql_filters{ServerId} ) {
push @sql_filters, ' Id IN ( SELECT StorageId FROM Monitors WHERE ServerId=? )'; push @sql_filters, ' ServerId = ?';
push @sql_values, $sql_filters{ServerId}; push @sql_values, $sql_filters{ServerId};
} }
@ -88,6 +88,7 @@ sub find {
my $filter = new ZoneMinder::Storage( $$db_filter{Id}, $db_filter ); my $filter = new ZoneMinder::Storage( $$db_filter{Id}, $db_filter );
push @results, $filter; push @results, $filter;
} # end while } # end while
Debug("SQL: $sql returned " . @results . ' results');
return @results; return @results;
} }

View File

@ -382,7 +382,7 @@ MAIN: while( $loop ) {
} # if USE_DEEP_STORAGE } # if USE_DEEP_STORAGE
Debug( 'Got '.int(keys(%$fs_events))." filesystem events for monitor $monitor_dir\n" ); Debug( 'Got '.int(keys(%$fs_events))." filesystem events for monitor $monitor_dir\n" );
#delete_empty_directories( $monitor_dir ); delete_empty_directories($monitor_dir);
} # end foreach monitor } # end foreach monitor
if ( $cleaned ) { if ( $cleaned ) {
@ -879,26 +879,30 @@ sub deleteSwapImage {
sub delete_empty_directories { sub delete_empty_directories {
my $DIR; my $DIR;
Debug("delete_empty_directories $_[0]");
if ( !opendir($DIR, $_[0]) ) { if ( !opendir($DIR, $_[0]) ) {
Error("delete_empty_directories: Can't open directory '".getcwd()."/$_[0]': $!" ); Error("delete_empty_directories: Can't open directory '".getcwd()."/$_[0]': $!" );
return; return;
} }
my @contents = map { $_ eq '.' or $_ eq '..' ? () : $_ } readdir( $DIR ); my @contents = map { ( $_ eq '.' or $_ eq '..' ) ? () : $_ } readdir( $DIR );
Debug("delete_empty_directories $_[0] has " . @contents .' entries:' . ( @contents < 2 ? join(',',@contents) : '' ));
my @dirs = map { -d $_[0].'/'.$_ ? $_ : () } @contents; my @dirs = map { -d $_[0].'/'.$_ ? $_ : () } @contents;
if ( @dirs ) { if ( @dirs ) {
Debug("Have " . @dirs . " dirs");
foreach ( @dirs ) { foreach ( @dirs ) {
delete_empty_directories( $_[0].'/'.$_ ); delete_empty_directories( $_[0].'/'.$_ );
} }
#Reload, since we may now be empty #Reload, since we may now be empty
rewinddir $DIR; rewinddir $DIR;
@contents = map { $_ eq '.' or $_ eq '..' ? () : $_ } readdir( $DIR ); @contents = map { ($_ eq '.' or $_ eq '..') ? () : $_ } readdir( $DIR );
}
if ( ! @contents ) {
( my $dir ) = ( $_[0] =~ /^(.*)$/ );
unlink $dir;
} }
closedir($DIR); closedir($DIR);
if ( ! @contents ) {
( my $dir ) = ( $_[0] =~ /^(.*)$/ );
Debug("Unlinking $dir because it's empty");
if ( ! rmdir $dir ) {
Error("Unable to unlink $dir: $!");
}
}
} # end sub delete_empty_directories } # end sub delete_empty_directories
1; 1;

View File

@ -353,6 +353,9 @@ VideoStore::~VideoStore() {
// The codec queues data. We need to send a flush command and out // The codec queues data. We need to send a flush command and out
// whatever we get. Failures are not fatal. // whatever we get. Failures are not fatal.
AVPacket pkt; AVPacket pkt;
// Without these we seg fault I don't know why.
pkt.data = NULL;
pkt.size = 0;
av_init_packet(&pkt); av_init_packet(&pkt);
while (1) { while (1) {

View File

@ -532,7 +532,7 @@ class Event {
$file = $backTrace[1]['file']; $file = $backTrace[1]['file'];
$line = $backTrace[1]['line']; $line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Event::find from $file:$line"); Error("Invalid value for limit($limit) passed to Event::find from $file:$line");
return; return array();
} }
} }
} }

View File

@ -145,7 +145,7 @@ public $defaults = array(
$file = $backTrace[1]['file']; $file = $backTrace[1]['file'];
$line = $backTrace[1]['line']; $line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Filter::find from $file:$line"); Error("Invalid value for limit($limit) passed to Filter::find from $file:$line");
return; return array();
} }
} }
} }

View File

@ -91,7 +91,7 @@ class Group {
$file = $backTrace[1]['file']; $file = $backTrace[1]['file'];
$line = $backTrace[1]['line']; $line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Group::find from $file:$line"); Error("Invalid value for limit($limit) passed to Group::find from $file:$line");
return; return array();
} }
} }
} # end if options } # end if options

View File

@ -312,7 +312,7 @@ private $control_fields = array(
$file = $backTrace[1]['file']; $file = $backTrace[1]['file'];
$line = $backTrace[1]['line']; $line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); Error("Invalid value for limit($limit) passed to Control::find from $file:$line");
return; return array();
} }
} }
} }

View File

@ -98,7 +98,7 @@ class Server {
$file = $backTrace[1]['file']; $file = $backTrace[1]['file'];
$line = $backTrace[1]['line']; $line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Server::find from $file:$line"); Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
return; return array();
} }
} }
} }
@ -106,6 +106,7 @@ class Server {
if ( $results ) { if ( $results ) {
return array_map( function($id){ return new Server($id); }, $results ); return array_map( function($id){ return new Server($id); }, $results );
} }
return array();
} }
public static function find_one( $parameters = array() ) { public static function find_one( $parameters = array() ) {

View File

@ -117,7 +117,7 @@ class Storage {
$file = $backTrace[1]['file']; $file = $backTrace[1]['file'];
$line = $backTrace[1]['line']; $line = $backTrace[1]['line'];
Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); Error("Invalid value for limit($limit) passed to Control::find from $file:$line");
return; return array();
} }
} # end if limit } # end if limit
} # end if options } # end if options

View File

@ -48,7 +48,7 @@ $scheme_options = array(
'Shallow' => translate('Shallow'), 'Shallow' => translate('Shallow'),
); );
$servers = Server::find_all( null, array('order'=>'lower(Name)') ); $servers = Server::find( null, array('order'=>'lower(Name)') );
$ServersById = array(); $ServersById = array();
foreach ( $servers as $S ) { foreach ( $servers as $S ) {
$ServersById[$S->Id()] = $S; $ServersById[$S->Id()] = $S;