Allow long paths on windows

If you start PFERD a few folders deep in your home directory, it is
quite easy to reach the maximum path length limit on Windows (260
chars). This patch opts in to long paths ("\\?\" prefix) which lift that
restriction at the cost of ugly path names.
This commit is contained in:
I-Al-Istannen 2020-07-24 09:22:51 +00:00
parent 41cbcc509c
commit a3e1864a26

View File

@ -5,6 +5,7 @@ A organizer is bound to a single directory.
import filecmp
import logging
import os
import shutil
from pathlib import Path, PurePath
from typing import List, Optional, Set
@ -44,6 +45,15 @@ class Organizer(Location):
(e.g. update the timestamp), the path is also returned in this case.
In all other cases (ignored, not overwritten, etc.) this method returns None.
"""
# Windows limits the path length to 260 for *some* historical reason
# If you want longer paths, you will have to add the "\\?\" prefix in front of
# your path...
# See:
# https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
if os.name == 'nt':
src_absolute = Path("\\\\?\\" + str(src.resolve()))
dst_absolute = Path("\\\\?\\" + str(self.resolve(dst)))
else:
src_absolute = src.resolve()
dst_absolute = self.resolve(dst)