diff --git a/CHANGELOG.md b/CHANGELOG.md index 658d9cc354..5858518911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - **depends:** Rewrite 'depends.ps1' ([#4638](https://github.com/ScoopInstaller/Scoop/issues/4638)) - **depends:** Keep bucket in 'Get-Dependency()' ([#4673](https://github.com/ScoopInstaller/Scoop/issues/4673)) - **mklink:** Use 'New-Item' instead of 'mklink' ([#4690](https://github.com/ScoopInstaller/Scoop/issues/4690)) +- **rmdir:** Use 'Remove-Item' instead of 'rmdir' ([#4691](https://github.com/ScoopInstaller/Scoop/issues/4691)) ### Builds diff --git a/lib/install.ps1 b/lib/install.ps1 index 5d7375c7a6..c414c98803 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -1192,10 +1192,10 @@ function unlink_persist_data($dir) { # remove read-only attribute on the link attrib -R /L $filepath # remove the junction - & "$env:COMSPEC" /c "rmdir /s /q `"$filepath`"" + Remove-Item -Path $filepath -Recurse -Force -ErrorAction SilentlyContinue } else { # remove the hard link - & "$env:COMSPEC" /c "del `"$filepath`"" + Remove-Item -Path $filepath -Force -ErrorAction SilentlyContinue } } } diff --git a/lib/psmodules.ps1 b/lib/psmodules.ps1 index 539f1b47ee..fc32e99425 100644 --- a/lib/psmodules.ps1 +++ b/lib/psmodules.ps1 @@ -2,28 +2,28 @@ $modulesdir = "$scoopdir\modules" function install_psmodule($manifest, $dir, $global) { $psmodule = $manifest.psmodule - if(!$psmodule) { return } + if (!$psmodule) { return } - if($global) { - abort "Installing PowerShell modules globally is not implemented!" + if ($global) { + abort 'Installing PowerShell modules globally is not implemented!' } $modulesdir = ensure $modulesdir ensure_in_psmodulepath $modulesdir $global $module_name = $psmodule.name - if(!$module_name) { + if (!$module_name) { abort "Invalid manifest: The 'name' property is missing from 'psmodule'." } $linkfrom = "$modulesdir\$module_name" - write-host "Installing PowerShell module '$module_name'" + Write-Host "Installing PowerShell module '$module_name'" - write-host "Linking $(friendly_path $linkfrom) => $(friendly_path $dir)" + Write-Host "Linking $(friendly_path $linkfrom) => $(friendly_path $dir)" - if(test-path $linkfrom) { + if (Test-Path $linkfrom) { warn "$(friendly_path $linkfrom) already exists. It will be replaced." - & "$env:COMSPEC" /c "rmdir `"$linkfrom`"" + Remove-Item -Path $linkfrom -Force -ErrorAction SilentlyContinue } New-Item -Path $linkfrom -ItemType Junction -Value $dir | Out-Null @@ -31,27 +31,27 @@ function install_psmodule($manifest, $dir, $global) { function uninstall_psmodule($manifest, $dir, $global) { $psmodule = $manifest.psmodule - if(!$psmodule) { return } + if (!$psmodule) { return } $module_name = $psmodule.name - write-host "Uninstalling PowerShell module '$module_name'." + Write-Host "Uninstalling PowerShell module '$module_name'." $linkfrom = "$modulesdir\$module_name" - if(test-path $linkfrom) { - write-host "Removing $(friendly_path $linkfrom)" - $linkfrom = resolve-path $linkfrom - & "$env:COMSPEC" /c "rmdir `"$linkfrom`"" + if (Test-Path $linkfrom) { + Write-Host "Removing $(friendly_path $linkfrom)" + $linkfrom = Resolve-Path $linkfrom + Remove-Item -Path $linkfrom -Force -ErrorAction SilentlyContinue } } function ensure_in_psmodulepath($dir, $global) { $path = env 'psmodulepath' $global - if(!$global -and $null -eq $path) { + if (!$global -and $null -eq $path) { $path = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules" } $dir = fullpath $dir - if($path -notmatch [regex]::escape($dir)) { - write-output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path." + if ($path -notmatch [Regex]::Escape($dir)) { + Write-Output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path." env 'psmodulepath' $global "$dir;$path" # for future sessions... $env:psmodulepath = "$dir;$env:psmodulepath" # for this session