mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-10-18 20:57:00 -04:00
Implement delete_empty_subdirs that uses delete_empty_directories. The idea is to use it on the monitor dir so that the monitor dir gets left behind and not deleted when there are no events
This commit is contained in:
1 parent
5d8b915c2b
commit
95bcac4c5a
1 file changed
+19
-1
+19
-1
@@ -386,7 +386,7 @@ MAIN: while( $loop ) {
|
||||
} # if USE_DEEP_STORAGE
|
||||
Debug( 'Got '.int(keys(%$fs_events))." filesystem events for monitor $monitor_dir\n" );
|
||||
|
||||
delete_empty_directories($$Storage{Path}.'/'.$monitor_dir);
|
||||
delete_empty_subdirs($$Storage{Path}.'/'.$monitor_dir);
|
||||
} # end foreach monitor
|
||||
|
||||
if ( $cleaned ) {
|
||||
@@ -885,6 +885,24 @@ sub deleteSwapImage {
|
||||
}
|
||||
}
|
||||
|
||||
# Deletes empty sub directories of the given path.
|
||||
# Does not delete the path if empty. Is not meant to be recursive.
|
||||
sub delete_empty_subdirs {
|
||||
my $DIR;
|
||||
if ( !opendir($DIR, $_[0]) ) {
|
||||
Error("delete_empty_directories: Can't open directory '".getcwd()."/$_[0]': $!" );
|
||||
return;
|
||||
}
|
||||
my @contents = map { ( $_ eq '.' or $_ eq '..' ) ? () : $_ } readdir( $DIR );
|
||||
Debug("delete_empty_subdirectories $_[0] has " . @contents .' entries:' . ( @contents < 2 ? join(',',@contents) : '' ));
|
||||
my @dirs = map { -d $_[0].'/'.$_ ? $_ : () } @contents;
|
||||
Debug("Have " . @dirs . " dirs");
|
||||
foreach ( @dirs ) {
|
||||
delete_empty_directories( $_[0].'/'.$_ );
|
||||
}
|
||||
closedir($DIR);
|
||||
}
|
||||
|
||||
sub delete_empty_directories {
|
||||
my $DIR;
|
||||
if ( !opendir($DIR, $_[0]) ) {
|
||||
|
||||
Reference in new issue
Block a user