Skip to content
New issue

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

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

Already on GitHub? # to your account

refactor(mklink): Use 'New-Item' instead of 'mklink' #4690

Merged
merged 2 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 @@ -27,6 +27,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))

### Builds

Expand Down
16 changes: 8 additions & 8 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ function link_current($versiondir) {
& "$env:COMSPEC" /c rmdir $currentdir
}

& "$env:COMSPEC" /c mklink /j $currentdir $versiondir | out-null
New-Item -Path $currentdir -ItemType Junction -Value $versiondir | Out-Null
attrib $currentdir +R /L
return $currentdir
}
Expand Down Expand Up @@ -1154,15 +1154,15 @@ function persist_data($manifest, $original_dir, $persist_dir) {
if (Test-Path $source) {
Move-Item -Force $source "$source.original"
}
# we don't have persist data in the store, move the source to target, then create link
# we don't have persist data in the store, move the source to target, then create link
} elseif (Test-Path $source) {
# ensure target parent folder exist
ensure (Split-Path -Path $target) | Out-Null
Move-Item $source $target
# we don't have neither source nor target data! we need to crate an empty target,
# but we can't make a judgement that the data should be a file or directory...
# so we create a directory by default. to avoid this, use pre_install
# to create the source file before persisting (DON'T use post_install)
# we don't have neither source nor target data! we need to crate an empty target,
# but we can't make a judgement that the data should be a file or directory...
# so we create a directory by default. to avoid this, use pre_install
# to create the source file before persisting (DON'T use post_install)
} else {
$target = New-Object System.IO.DirectoryInfo($target)
ensure $target | Out-Null
Expand All @@ -1171,11 +1171,11 @@ function persist_data($manifest, $original_dir, $persist_dir) {
# create link
if (is_directory $target) {
# target is a directory, create junction
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | out-null
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
attrib $source +R /L
} else {
# target is a file, create hard link
& "$env:COMSPEC" /c "mklink /h `"$source`" `"$target`"" | out-null
New-Item -Path $source -ItemType HardLink -Value $target | Out-Null
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/psmodules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function install_psmodule($manifest, $dir, $global) {
& "$env:COMSPEC" /c "rmdir `"$linkfrom`""
}

& "$env:COMSPEC" /c "mklink /j `"$linkfrom`" `"$dir`"" | out-null
New-Item -Path $linkfrom -ItemType Junction -Value $dir | Out-Null
}

function uninstall_psmodule($manifest, $dir, $global) {
Expand Down