mirror of
https://github.com/clearml/clearml
synced 2025-01-31 00:56:57 +00:00
Fix maxfile attribute dropped in psutil 6.0.0 causing an error to be printed
This commit is contained in:
parent
9611e5c486
commit
696af6e76b
@ -7,19 +7,22 @@ import psutil
|
||||
|
||||
def get_filename_max_length(dir_path):
|
||||
# type: (str) -> int
|
||||
default = 255 # Common filesystems like NTFS, EXT4 and HFS+ limited with 255
|
||||
try:
|
||||
dir_path = pathlib2.Path(os.path.abspath(dir_path))
|
||||
if platform == "win32":
|
||||
# noinspection PyBroadException
|
||||
dir_drive = dir_path.drive
|
||||
for drv in psutil.disk_partitions():
|
||||
if drv.device.startswith(dir_drive):
|
||||
return drv.maxfile
|
||||
# The maxfile attribute is only available in psutil >=5.7.4,<6.0.0
|
||||
return getattr(drv, "maxfile", default)
|
||||
elif platform in ("linux", "darwin"):
|
||||
return os.statvfs(dir_path).f_namemax
|
||||
except Exception as err:
|
||||
print(err)
|
||||
|
||||
return 255 # Common filesystems like NTFS, EXT4 and HFS+ limited with 255
|
||||
return default
|
||||
|
||||
|
||||
def is_path_traversal(target_folder, relative_path):
|
||||
|
Loading…
Reference in New Issue
Block a user