avoid exceptions when the user's config points to nonexistent directories

This commit is contained in:
Josh Holtrop 2013-10-18 15:45:58 -04:00
parent e959d11cd0
commit 17f99805f0

View File

@ -46,10 +46,13 @@ def get_server_name(config, fname):
path = path.replace('\\', '/')
if path.endswith('/*'):
path = path[:-2]
for dirent in os.listdir(path):
query_path = os.path.join(path, dirent)
if os.path.isdir(query_path) and path_contains_file(query_path, fname):
return name.replace('*', dirent)
try:
for dirent in os.listdir(path):
query_path = os.path.join(path, dirent)
if os.path.isdir(query_path) and path_contains_file(query_path, fname):
return name.replace('*', dirent)
except:
pass
else:
if path_contains_file(path, fname):
return name.replace('*', os.path.basename(path))