Windows: UNC paths get an invalid \?\ prefix (longpath / data path), WinError 123
Windows: UNC paths get a malformed \\?\ prefix (\\?\\\server\share\...), which Windows rejects with WinError 123; sys_path.longpath() and the module-level data path both do it.
(Edited: my first version of this text lost most of its backslashes, so the prefixes looked wrong. Below they are correct.)
sys_path.longpath() returns PREFIX + os.path.normpath(path) for every path, and sys_path.py (line ~80) does __data_path = PREFIX + __data_path for the data directory. PREFIX is \\?\ (4 characters: \, \, ?, \). For a drive path that is right; for a UNC path such as \\server\share\x the extended-length form must be \\?\UNC\server\share\x, not \\?\ + \\server\share\x (which gives \\?\\\server\share\x).
Verified in Sublime Text 4200 on Windows 11 with the local admin share as a harmless UNC path (read-only calls only):
B = chr(92)
unc = B + B + 'localhost' + B + 'C$' + B + 'Windows' + B + 'System32' # \\localhost\C$\Windows\System32
sp.PREFIX # '\\\\?\\' i.e. the 4 characters \\?\
os.path.isdir(unc) # True
l = sys_path.longpath(unc) # \\?\\\localhost\C$\Windows\System32
os.path.isdir(l) # False
os.listdir(l) # OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect
good = B + B + '?' + B + 'UNC' + B + 'localhost' + B + 'C$' + B + 'Windows' + B + 'System32' # \\?\UNC\localhost\C$\Windows\System32
os.path.isdir(good) # True (the correct form)
sys_path.longpath('C:' + B + 'Windows') # \\?\C:\Windows (drive paths are fine)
shortpath() has the mirror problem: it strips only \\?\, so shortpath(r'\\?\UNC\server\share\x') returns UNC\server\share\x.
Where this bites: if Sublime Text's data directory itself is on a UNC path (a folder-redirected/roaming %APPDATA% such as \\fileserver\profiles$\user\AppData\Roaming, or a portable install on a network share), __data_path gets the invalid prefix, so every path Package Control builds from it (packages_path(), installed_packages_path(), trash_path(), lib paths, cache) fails with WinError 123 in every file operation.
Fix: in longpath() and the data-path prefixing, use \\?\UNC\ + path[2:] when path starts with \\ (and isn't already \\?\ or \\.\), and make shortpath() invert that (\\?\UNC\x -> \\x).
The reproduction or proposed fixes are invalid. \?\UNC is not a valid prefix.
Sorry, that was my fault: the first version of the issue text lost most of its backslashes when it was posted, so it wrote the prefixes as \?\ and \?\UNC\... (one leading backslash), which of course is not valid. I have edited the description.
The actual forms are \\?\UNC\server\share\... (valid) versus what longpath() produces for a UNC path, \\?\ + \\server\share\... = \\?\\\server\share\... (invalid). Checked again just now with the characters built in code (no escaping involved), on the built-in admin share:
sys_path.PREFIX -> '\\\\?\\' (the 4 chars \\?\)
longpath(r'\\localhost\C$\Windows\System32') -> \\?\\\localhost\C$\Windows\System32
os.path.isdir(<that>) -> False, os.listdir -> WinError 123
os.path.isdir(r'\\?\UNC\localhost\C$\Windows\System32') -> True
If you still think the premise is wrong after reading the corrected text, please say so and I will close it.