Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(current): Remove 'current' while it's not a junction #4687

Merged
merged 3 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

& "$env:COMSPEC" /c mklink /j $currentdir $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