Skip to content

gh-158068: venv: do not clear env_dir if it's a symlink or a file - #158075

Open
frenzymadness wants to merge 1 commit into
python:mainfrom
frenzymadness:venv_clean_158068
Open

frenzymadness wants to merge 1 commit into
python:mainfrom
frenzymadness:venv_clean_158068

Conversation

@frenzymadness

@frenzymadness frenzymadness commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Previously venv --clear called clear_directory() on env_dir whenever it existed. If env_dir was a symlink to a directory, this followed the link and wiped the contents of the target directory -- possible data loss. If it was a regular file it failed with an unclear error.

Now creating a venv over an existing symlink or file raises ValueError before anything is removed, matching the check already done for the non-clear case.

Previously `venv --clear` called clear_directory() on env_dir whenever
it existed. If env_dir was a symlink to a directory, this followed the
link and wiped the contents of the target directory -- possible data
loss. If it was a regular file it failed with an unclear error.

Now creating a venv over an existing symlink or file raises ValueError
before anything is removed, matching the check already done for the
non-clear case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant