Skip to content

Commit

Permalink
Use rmtree instead of spawning rmdir on Windows
Browse files Browse the repository at this point in the history
This code dates all the way back to
7cb6561. It's not clear why this code
decides to spawn an rmdir process on Windows instead of simply calling
`shutil.rmtree()` directly.
  • Loading branch information
dechamps committed Dec 28, 2023
1 parent 5a16aac commit ac6027a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## dev

- Delete directories directly instead of spawning rmdir on Windows
- Fix "Failed to delete" error when using Microsoft Store Python
- Fix "No pyvenv.cfg file" error when using Microsoft Store Python (#1164)
- Add `--quiet` and `--verbose` options for the `pipx` subcommands
Expand Down
7 changes: 1 addition & 6 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ def rmdir(path: Path, safe_rm: bool = True) -> None:

logger.info(f"removing directory {path}")
try:
if WINDOWS:
# The packaged app (Microsoft Store) version of Python uses path redirections, but `rmdir` won't follow
# these, so use realpath() to manually apply the redirection first.
os.system(f'rmdir /S /Q "{os.path.realpath(path)}"')
else:
shutil.rmtree(path)
shutil.rmtree(path)
except FileNotFoundError:
pass

Expand Down

0 comments on commit ac6027a

Please sign in to comment.