Prevent duplicate binPath in PATH environment variable

- Check if binPath is already in PATH before adding it.
- Add binPath to PATH only if it's not already present.
- Log a message when binPath is added to PATH.
This commit is contained in:
bobo.yang 2023-06-16 09:08:51 +08:00
parent 1bb215f51b
commit 35215a7fb6

View File

@ -62,5 +62,8 @@ export function getPipxEnvironmentPath(pythonCommand: string): string | null {
function updateEnvironmentPath(binPath: string): void { function updateEnvironmentPath(binPath: string): void {
// Add BIN path to PATH // Add BIN path to PATH
process.env.PATH = `${binPath}:${process.env.PATH}`; if (process.env.PATH?.indexOf(binPath) === undefined) {
process.env.PATH = `${binPath}:${process.env.PATH}`;
logger.channel()?.info(`Added ${binPath} to PATH.`);
}
} }