2525import re
2626import warnings
2727import signal
28- from datetime import datetime , timedelta
28+ from datetime import datetime , timedelta , timezone
2929from threading import Thread , Lock , current_thread
3030from concurrent import futures
3131from queue import Queue
@@ -236,7 +236,7 @@ def log_stats_thread(root):
236236 start = time .time ()
237237
238238 while True :
239- time .sleep (3 )
239+ time .sleep (10 )
240240 if not scan_paths :
241241 continue
242242 timenow = time .time ()
@@ -475,7 +475,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
475475
476476 # check for invalid time stamps
477477 try :
478- mtime = datetime .utcfromtimestamp (int (f_stat .st_mtime )).isoformat ()
478+ mtime = datetime .fromtimestamp (int (f_stat .st_mtime ), timezone . utc ).isoformat ()
479479 except ValueError :
480480 logmsg = '[{0}] MTIME TIMESTAMP WARNING {1}' .format (thread , os .path .join (parent_path , file_name ))
481481 logger .warning (logmsg )
@@ -486,7 +486,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
486486 pass
487487
488488 try :
489- atime = datetime .utcfromtimestamp (int (f_stat .st_atime )).isoformat ()
489+ atime = datetime .fromtimestamp (int (f_stat .st_atime ), tz = timezone . utc ).isoformat ()
490490 except ValueError :
491491 logmsg = '[{0}] ATIME TIMESTAMP WARNING {1}' .format (thread , os .path .join (parent_path , file_name ))
492492 logger .warning (logmsg )
@@ -497,7 +497,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
497497 pass
498498
499499 try :
500- ctime = datetime .utcfromtimestamp (int (f_stat .st_ctime )).isoformat ()
500+ ctime = datetime .fromtimestamp (int (f_stat .st_ctime ), timezone . utc ).isoformat ()
501501 except ValueError :
502502 logmsg = '[{0}] CTIME TIMESTAMP WARNING {1}' .format (thread , os .path .join (parent_path , file_name ))
503503 logger .warning (logmsg )
@@ -635,7 +635,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
635635
636636 # handle timestamp errors in s3fs and possibly other fuse mounts
637637 try :
638- mtime = datetime .utcfromtimestamp (int (d_stat .st_mtime )).isoformat ()
638+ mtime = datetime .fromtimestamp (int (d_stat .st_mtime ), timezone . utc ).isoformat ()
639639 except ValueError :
640640 logmsg = '[{0}] MTIME TIMESTAMP WARNING {1}' .format (thread , os .path .join (parent_path , file_name ))
641641 logger .warning (logmsg )
@@ -646,7 +646,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
646646 pass
647647
648648 try :
649- atime = datetime .utcfromtimestamp (int (d_stat .st_atime )).isoformat ()
649+ atime = datetime .fromtimestamp (int (d_stat .st_atime ), timezone . utc ).isoformat ()
650650 except ValueError :
651651 logmsg = '[{0}] ATIME TIMESTAMP WARNING {1}' .format (thread , os .path .join (parent_path , file_name ))
652652 logger .warning (logmsg )
@@ -657,7 +657,7 @@ def get_tree_size(executor, thread, root, top, path, sizes, inodes, depth=0, max
657657 pass
658658
659659 try :
660- ctime = datetime .utcfromtimestamp (int (d_stat .st_ctime )).isoformat ()
660+ ctime = datetime .fromtimestamp (int (d_stat .st_ctime ), timezone . utc ).isoformat ()
661661 except ValueError :
662662 logmsg = '[{0}] CTIME TIMESTAMP WARNING {1}' .format (thread , os .path .join (parent_path , file_name ))
663663 logger .warning (logmsg )
@@ -838,7 +838,7 @@ def crawl_tree(root, top, maxdepth, sizes, inodes):
838838 if config ['LOGTOFILE' ]: logger_warn .critical (logmsg , exc_info = 1 )
839839 close_app_critical_error ()
840840 scandir_walk_time = time .time () - scandir_walk_start
841- end_time = datetime .utcnow ( ).strftime ("%Y-%m-%dT%H:%M:%S" )
841+ end_time = datetime .now ( timezone . utc ).strftime ("%Y-%m-%dT%H:%M:%S" )
842842
843843 # check if directory is empty or all files/dirs excluded
844844 if not root in sizes :
@@ -903,7 +903,7 @@ def banner():
903903 'I didn\' t even know that was there.' ,
904904 'Bringing light to the darkness.' ]
905905
906- print (r """\u001b[31;1m
906+ print ("""\u001b [31;1m
907907 _ _ _
908908 | (_) | |
909909 __| |_ ___| | _______ _____ _ __
@@ -1024,8 +1024,6 @@ def log_setup():
10241024 help = 'use alternate scanner module in scanners/' )
10251025 parser .add_option ('--threads' , type = int ,
10261026 help = 'crawl scan threads (overrides config maxthreads setting)' )
1027- parser .add_option ('--threaddepth' , type = int ,
1028- help = 'crawl scan thread directory depth (overrides config threaddirdepth setting) (ESSENTIAL VER)' )
10291027 parser .add_option ('-v' , '--verbose' , action = 'store_true' ,
10301028 help = 'verbose output' )
10311029 parser .add_option ('-V' , '--vverbose' , action = 'store_true' ,
@@ -1100,11 +1098,6 @@ def log_setup():
11001098 logger .error (logmsg )
11011099 if config ['LOGTOFILE' ]: logger_warn .error (logmsg )
11021100 sys .exit (1 )
1103- if options .threaddepth :
1104- logmsg = 'Using --threaddepth cli option to set crawl scan thread directory depth requires diskover Essential version.'
1105- logger .error (logmsg )
1106- if config ['LOGTOFILE' ]: logger_warn .error (logmsg )
1107- sys .exit (1 )
11081101
11091102 # get top path arg
11101103 if args :
@@ -1154,17 +1147,24 @@ def log_setup():
11541147 sys .exit (1 )
11551148
11561149 # check if tree_dir is empty or all items excluded
1157- dc = 0
1150+ empty = True
11581151 if IS_WIN and not options .altscanner :
11591152 tree_dir = get_win_path (tree_dir )
1160- for entry in os .scandir (tree_dir ):
1161- if entry .is_symlink ():
1162- pass
1163- elif entry .is_dir () and not dir_excluded (entry .path ):
1164- dc += 1
1165- elif not file_excluded (entry .name ):
1166- dc += 1
1167- if dc == 0 :
1153+ try :
1154+ for entry in os .scandir (tree_dir ):
1155+ if entry .is_symlink ():
1156+ pass
1157+ elif entry .is_dir () and not dir_excluded (entry .path ):
1158+ empty = False
1159+ break
1160+ elif not file_excluded (entry .name ):
1161+ empty = False
1162+ break
1163+ except OSError as e :
1164+ logmsg = 'OS ERROR: {0}' .format (e )
1165+ logger .error (logmsg )
1166+ raise
1167+ if empty :
11681168 logger .info ('{0} is empty or all items excluded! Nothing to crawl.' .format (tree_dir ))
11691169 sys .exit (0 )
11701170
@@ -1238,7 +1238,7 @@ def log_setup():
12381238 skipfilecount [tree_dir ] = 0
12391239 total_doc_count [tree_dir ] = 0
12401240 inodecount [tree_dir ] = 0
1241- start_time = datetime .utcnow ( ).strftime ("%Y-%m-%dT%H:%M:%S" )
1241+ start_time = datetime .now ( timezone . utc ).strftime ("%Y-%m-%dT%H:%M:%S" )
12421242 index_info_crawlstart (es , options .index , tree_dir , start_time , version , alt_scanner )
12431243
12441244 # start thread for stat logging
0 commit comments