Skip to content

Commit

Permalink
fix(current): Remove 'current' while it's not a junction (#4687)
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven authored Jan 25, 2022
1 parent 98ea7a5 commit 4a9efaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- **autoupdate:** Allow checksum file that contains whitespaces ([#4619](https://github.com/ScoopInstaller/Scoop/issues/4619))
- **config:** Allow scoop config use Unicode characters ([#4631](https://github.com/ScoopInstaller/Scoop/issues/4631))
- **current:** Remove 'current' while it's not a junction ([#4687](https://github.com/ScoopInstaller/Scoop/issues/4687))
- **depends:** Prevent error on no URL ([#4595](https://github.com/ScoopInstaller/Scoop/issues/4595))
- **depends:** Check if extractor is available ([#4042](https://github.com/ScoopInstaller/Scoop/issues/4042))
- **decompress:** Fix nested Zstd archive extraction ([#4608](https://github.com/ScoopInstaller/Scoop/issues/4608))
Expand Down
18 changes: 9 additions & 9 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -911,20 +911,20 @@ function current_dir($versiondir) {
# Returns the 'current' junction directory if in use, otherwise
# the version directory.
function link_current($versiondir) {
if(get_config NO_JUNCTIONS) { return $versiondir }
if (get_config NO_JUNCTIONS) { return $versiondir }

$currentdir = current_dir $versiondir

write-host "Linking $(friendly_path $currentdir) => $(friendly_path $versiondir)"
Write-Host "Linking $(friendly_path $currentdir) => $(friendly_path $versiondir)"

if($currentdir -eq $versiondir) {
if ($currentdir -eq $versiondir) {
abort "Error: Version 'current' is not allowed!"
}

if(test-path $currentdir) {
if (Test-Path $currentdir) {
# remove the junction
attrib -R /L $currentdir
& "$env:COMSPEC" /c rmdir $currentdir
Remove-Item $currentdir -Recurse -Force -ErrorAction Stop
}

New-Item -Path $currentdir -ItemType Junction -Value $versiondir | Out-Null
Expand All @@ -938,17 +938,17 @@ function link_current($versiondir) {
# Returns the 'current' junction directory (if it exists),
# otherwise the normal version directory.
function unlink_current($versiondir) {
if(get_config NO_JUNCTIONS) { return $versiondir }
if (get_config NO_JUNCTIONS) { return $versiondir }
$currentdir = current_dir $versiondir

if(test-path $currentdir) {
write-host "Unlinking $(friendly_path $currentdir)"
if (Test-Path $currentdir) {
Write-Host "Unlinking $(friendly_path $currentdir)"

# remove read-only attribute on link
attrib $currentdir -R /L

# remove the junction
& "$env:COMSPEC" /c "rmdir `"$currentdir`""
Remove-Item $currentdir -Recurse -Force -ErrorAction Stop
return $currentdir
}
return $versiondir
Expand Down

0 comments on commit 4a9efaa

Please sign in to comment.