Fix max path length calculations
This commit is contained in:
parent
6dd17c8762
commit
2dd446a402
1 changed files with 11 additions and 6 deletions
|
@ -130,14 +130,19 @@ class FileNameFormatter:
|
||||||
ending = possible_id.group(1) + ending
|
ending = possible_id.group(1) + ending
|
||||||
filename = filename[:possible_id.start()]
|
filename = filename[:possible_id.start()]
|
||||||
max_path = FileNameFormatter.find_max_path_length()
|
max_path = FileNameFormatter.find_max_path_length()
|
||||||
max_length_chars = 255 - len(ending)
|
max_file_part_length_chars = 255 - len(ending)
|
||||||
max_length_bytes = 255 - len(ending.encode('utf-8'))
|
max_file_part_length_bytes = 255 - len(ending.encode('utf-8'))
|
||||||
max_path_length = max_path - len(ending) - len(str(root)) - 1
|
max_path_length = max_path - len(ending) - len(str(root)) - 1
|
||||||
while any([len(filename) > max_length_chars,
|
|
||||||
len(filename.encode('utf-8')) > max_length_bytes,
|
out = Path(root, filename + ending)
|
||||||
len(filename) > max_path_length]):
|
while any([len(filename) > max_file_part_length_chars,
|
||||||
|
len(filename.encode('utf-8')) > max_file_part_length_bytes,
|
||||||
|
len(str(out)) > max_path_length,
|
||||||
|
]):
|
||||||
filename = filename[:-1]
|
filename = filename[:-1]
|
||||||
return Path(root, filename + ending)
|
out = Path(root, filename + ending)
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find_max_path_length() -> int:
|
def find_max_path_length() -> int:
|
||||||
|
|
Loading…
Reference in a new issue