mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
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:
parent
41cbcc509c
commit
a3e1864a26
@ -5,6 +5,7 @@ A organizer is bound to a single directory.
|
|||||||
|
|
||||||
import filecmp
|
import filecmp
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import List, Optional, Set
|
from typing import List, Optional, Set
|
||||||
@ -44,8 +45,17 @@ class Organizer(Location):
|
|||||||
(e.g. update the timestamp), the path is also returned in this case.
|
(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.
|
In all other cases (ignored, not overwritten, etc.) this method returns None.
|
||||||
"""
|
"""
|
||||||
src_absolute = src.resolve()
|
# Windows limits the path length to 260 for *some* historical reason
|
||||||
dst_absolute = self.resolve(dst)
|
# 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)
|
||||||
|
|
||||||
if not src_absolute.exists():
|
if not src_absolute.exists():
|
||||||
raise FileAcceptException("Source file does not exist")
|
raise FileAcceptException("Source file does not exist")
|
||||||
|
Loading…
Reference in New Issue
Block a user