Skip to content

Handle ENAMETOOLONG on macOS when clearing cache entries - #20933

Open
woodruffw wants to merge 5 commits into
mainfrom
ww/macos-long
Open

woodruffw wants to merge 5 commits into
mainfrom
ww/macos-long

Conversation

@woodruffw

@woodruffw woodruffw commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

WIP, I still need to clean this up + think about appropriate warning states.

Summary

Fixes #15569.

TL;DR: if a user runs uv cache clean (or similar) but their cache directory contains absolute paths that are pathologically long (longer than PATH_MAX=1024), walkdir will fail to materialize them before we have a chance to actually delete them.

The solution is to take their parent directory and remove each member relative to it. Rust's remove_dir_all does this robustly by using openat and unlinkat on macOS.

I think we could probably broaden this to Linux (and other Unix-likes?) as well. However the problem is less apparent there since PATH_MAX is even more pathological (4096).

I decided not to add a user warning here, since it's not really actionable.

Test Plan

Added integration tests.

@woodruffw woodruffw added the area:cache Caching of packages and metadata label Aug 3, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 3
  • Removed tests: 0
  • Changed suites: 1
uv::build: +3 / -0

Added:

  • uv::build::cache_long_paths::clean_handles_overlong_file_paths
  • uv::build::cache_long_paths::clean_handles_overlong_paths
  • uv::build::cache_long_paths::prune_handles_overlong_paths

Removed: none

@woodruffw

Copy link
Copy Markdown
Member Author

NB: I suspect BurntSushi/walkdir#217 is what we'll want longer-term here.

@woodruffw
woodruffw marked this pull request as ready for review August 4, 2026 18:05
@woodruffw
woodruffw requested review from EliteTK and zanieb August 4, 2026 18:05
Comment thread crates/uv/tests/build/cache_long_paths.rs Outdated
Comment thread crates/uv/tests/build/main.rs
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>

@EliteTK EliteTK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too fond of this kind of a workaround.

walkdir is a bit too established for an upstream fix to land in a way which would cleanly help here. I think a perfectly reasonable decision is to just write our own small walker for our purposes which gives you entries in a form which makes it easy to manipulate without needing to deal with long paths (of course for logging we'd still need to construct a path, which we can still do). I wouldn't mind fixing this (sounds like fun).

This PR does have two gaps though:

  • uv_distribution::prune: called for the sdists bucket, uses walkdir without this guard, since we extract into a shallower path and then rename, there's a chance we could still construct paths that end up too long.
  • find_archive_references: called for the sdists and wheels buckets, uses walkdir without this guard, but it skips src directories and thus is probably not realistically going to have an issue because of this.

@woodruffw

Copy link
Copy Markdown
Member Author

Yeah, it's kind of a sad workaround.

walkdir is a bit too established for an upstream fix to land in a way which would cleanly help here.

How do you mean? I think that PR linked above would address our specific problem, although it does involve a public API break on walkdir's side.

@woodruffw

woodruffw commented Aug 11, 2026 •

Copy link
Copy Markdown
Member Author

I'll see if I can lift the changes further here; I agree at minimum we should be guarding the prune case too.

This branch was previously deployed

1 inactive deployment
automations — 9a6dd20c Deployed Aug 7, 2026 by woodruffw via review / security review #44308
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cache Caching of packages and metadata

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv cache {clean, prune} fails with os error 63

3 participants