Skip to content

Commit 28ca55c

Browse files
niheavense35710
authored andcommitted
refactor(rmdir): Use 'Remove-Item' instead of 'rmdir' (ScoopInstaller#4691)
1 parent 9fc91d6 commit 28ca55c

3 files changed

Lines changed: 20 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- **depends:** Rewrite 'depends.ps1' ([#4638](https://github.com/ScoopInstaller/Scoop/issues/4638))
3131
- **depends:** Keep bucket in 'Get-Dependency()' ([#4673](https://github.com/ScoopInstaller/Scoop/issues/4673))
3232
- **mklink:** Use 'New-Item' instead of 'mklink' ([#4690](https://github.com/ScoopInstaller/Scoop/issues/4690))
33+
- **rmdir:** Use 'Remove-Item' instead of 'rmdir' ([#4691](https://github.com/ScoopInstaller/Scoop/issues/4691))
3334

3435
### Builds
3536

lib/install.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,10 @@ function unlink_persist_data($dir) {
11921192
# remove read-only attribute on the link
11931193
attrib -R /L $filepath
11941194
# remove the junction
1195-
& "$env:COMSPEC" /c "rmdir /s /q `"$filepath`""
1195+
Remove-Item -Path $filepath -Recurse -Force -ErrorAction SilentlyContinue
11961196
} else {
11971197
# remove the hard link
1198-
& "$env:COMSPEC" /c "del `"$filepath`""
1198+
Remove-Item -Path $filepath -Force -ErrorAction SilentlyContinue
11991199
}
12001200
}
12011201
}

lib/psmodules.ps1

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,56 @@ $modulesdir = "$scoopdir\modules"
22

33
function install_psmodule($manifest, $dir, $global) {
44
$psmodule = $manifest.psmodule
5-
if(!$psmodule) { return }
5+
if (!$psmodule) { return }
66

7-
if($global) {
8-
abort "Installing PowerShell modules globally is not implemented!"
7+
if ($global) {
8+
abort 'Installing PowerShell modules globally is not implemented!'
99
}
1010

1111
$modulesdir = ensure $modulesdir
1212
ensure_in_psmodulepath $modulesdir $global
1313

1414
$module_name = $psmodule.name
15-
if(!$module_name) {
15+
if (!$module_name) {
1616
abort "Invalid manifest: The 'name' property is missing from 'psmodule'."
1717
}
1818

1919
$linkfrom = "$modulesdir\$module_name"
20-
write-host "Installing PowerShell module '$module_name'"
20+
Write-Host "Installing PowerShell module '$module_name'"
2121

22-
write-host "Linking $(friendly_path $linkfrom) => $(friendly_path $dir)"
22+
Write-Host "Linking $(friendly_path $linkfrom) => $(friendly_path $dir)"
2323

24-
if(test-path $linkfrom) {
24+
if (Test-Path $linkfrom) {
2525
warn "$(friendly_path $linkfrom) already exists. It will be replaced."
26-
& "$env:COMSPEC" /c "rmdir `"$linkfrom`""
26+
Remove-Item -Path $linkfrom -Force -ErrorAction SilentlyContinue
2727
}
2828

2929
New-Item -Path $linkfrom -ItemType Junction -Value $dir | Out-Null
3030
}
3131

3232
function uninstall_psmodule($manifest, $dir, $global) {
3333
$psmodule = $manifest.psmodule
34-
if(!$psmodule) { return }
34+
if (!$psmodule) { return }
3535

3636
$module_name = $psmodule.name
37-
write-host "Uninstalling PowerShell module '$module_name'."
37+
Write-Host "Uninstalling PowerShell module '$module_name'."
3838

3939
$linkfrom = "$modulesdir\$module_name"
40-
if(test-path $linkfrom) {
41-
write-host "Removing $(friendly_path $linkfrom)"
42-
$linkfrom = resolve-path $linkfrom
43-
& "$env:COMSPEC" /c "rmdir `"$linkfrom`""
40+
if (Test-Path $linkfrom) {
41+
Write-Host "Removing $(friendly_path $linkfrom)"
42+
$linkfrom = Resolve-Path $linkfrom
43+
Remove-Item -Path $linkfrom -Force -ErrorAction SilentlyContinue
4444
}
4545
}
4646

4747
function ensure_in_psmodulepath($dir, $global) {
4848
$path = env 'psmodulepath' $global
49-
if(!$global -and $null -eq $path) {
49+
if (!$global -and $null -eq $path) {
5050
$path = "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
5151
}
5252
$dir = fullpath $dir
53-
if($path -notmatch [regex]::escape($dir)) {
54-
write-output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path."
53+
if ($path -notmatch [Regex]::Escape($dir)) {
54+
Write-Output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) PowerShell module path."
5555

5656
env 'psmodulepath' $global "$dir;$path" # for future sessions...
5757
$env:psmodulepath = "$dir;$env:psmodulepath" # for this session

0 commit comments

Comments
 (0)