Skip to content

Commit afb1fc1

Browse files
committed
Update diskover.py reduced time to check if directory empty at start of scan
Update diskover.py reduced time to check if directory empty at start of scan
1 parent b48403c commit afb1fc1

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

diskover/diskover.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,17 +1147,24 @@ def log_setup():
11471147
sys.exit(1)
11481148

11491149
# check if tree_dir is empty or all items excluded
1150-
dc = 0
1150+
empty = True
11511151
if IS_WIN and not options.altscanner:
11521152
tree_dir = get_win_path(tree_dir)
1153-
for entry in os.scandir(tree_dir):
1154-
if entry.is_symlink():
1155-
pass
1156-
elif entry.is_dir() and not dir_excluded(entry.path):
1157-
dc += 1
1158-
elif not file_excluded(entry.name):
1159-
dc += 1
1160-
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:
11611168
logger.info('{0} is empty or all items excluded! Nothing to crawl.'.format(tree_dir))
11621169
sys.exit(0)
11631170

0 commit comments

Comments
 (0)