Skip to content

uv cache clean fails on Windows when sdist contains special filenames #16586

@sunfkny

Description

@sunfkny

Summary

Moved from #15569 (comment)

Description

On Windows, when running uv add uwsgi, the build process fails (which is expected as uwsgi cannot compile on Windows). However, when subsequently running uv cache clean, the command fails because the cached sdist contains a file with a Windows-incompatible name (ending with a period).

Steps to Reproduce

On Windows, create a new project and add uwsgi.

uv init
uv add uwsgi

The build fails as expected since uwsgi is not supported on Windows.

Then run:

uv cache clean

Expected Behavior

uv cache clean should remove cached source distributions (sdists).

Actual Behavior

Clearing cache at: AppData\Local\uv\cache
error: Failed to clear cache at: AppData\Local\uv\cache
  Caused by: failed to remove file `C:\Users\root\AppData\Local\uv\cache\sdists-v9\index\3ba65c4f41aac3a1\uwsgi\2.0.31\l1w3t3Nrz8OnzxF6ri3eg\src\core\logging.`: The system cannot find the file specified. (os error 2)

Suggested Fix

Use logic similar to Python’s isreserved to detect and handle reserved or invalid Windows filenames before deletion.

When removing such files, use the extended \\?\ path prefix to bypass Win32 path normalization, which allows operations on paths exceeding MAX_PATH or containing characters normally restricted by the Win32 API (such as trailing dots or spaces).

Platform

Windows 11 24H2

Version

uv 0.9.7 (0adb444 2025-10-30)

Python version

Python 3.13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggreat writeupA wonderful example of a quality contribution 💜windowsSpecific to the Windows platform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions