Handle that os.pathconf is posix-only

This commit is contained in:
Jakub Roztocil 2016-03-17 16:14:14 +08:00
parent 5300b0b490
commit 557911b606

View File

@ -148,13 +148,17 @@ def trim_filename(filename, max_len):
def get_filename_max_length(directory):
max_len = 255
try:
max_len = os.pathconf(directory, 'PC_NAME_MAX')
except OSError as e:
if e.errno == errno.EINVAL:
max_len = 255
else:
raise
pathconf = os.pathconf
except AttributeError:
pass # non-posix
else:
try:
max_len = pathconf(directory, 'PC_NAME_MAX')
except OSError as e:
if e.errno != errno.EINVAL:
raise
return max_len