Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails with long network paths on Windows #11

Open
jessielw opened this issue Jun 17, 2024 · 0 comments
Open

Fails with long network paths on Windows #11

jessielw opened this issue Jun 17, 2024 · 0 comments

Comments

@jessielw
Copy link

jessielw commented Jun 17, 2024

I was testing this library out and it fails to write (just hangs) with very long Windows path names. Example path name that was failing.

\\JLW-UNRAID\dl_share\downloads_nvme_temp\random_folder\downloads\Hostage.2005.Remastered.BluRay.1080p.DTS-HD.MA.5.1.AVC.HYBRID.REMUX-FraMeSToR\Hostage.2005.Remastered.BluRay.1080p.DTS-HD.MA.5.1.AVC.HYBRID.REMUX-FraMeSToRä_temp\Hostage.2005.BluRay.720p.DD.2.0.x264-group_images\img_comparison\%da_source__%d.png

Edit if I create a small function to convert this to a UNC path it works fine.

def convert_to_extended_path(path: str) -> str:
    """
    Convert a standard or UNC path to an extended-length path
    with the \\?\ prefix for Windows if needed.

    Parameters:
    - path (str): The original file path.

    Returns:
    - str: The extended-length file path if needed, or the original path.
    """
    # Ensure we're manipulating a string
    path = str(path)
    
    # Normalize slashes to backslashes
    path = path.replace('/', '\\')    

    # Check if the path is already an extended path
    if path.startswith("\\\\?\\"):
        return path

    # Check if the path length exceeds 260 characters
    if len(path) > 260 or any(ord(char) > 127 for char in path):
        # Check if the path is a UNC path (starts with \\)
        if path.startswith("\\\\"):
            extended_path = "\\\\?\\UNC" + path[1:]
        else:
            extended_path = "\\\\?\\" + path
        return extended_path

    return path

Is this intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant