Skip to content

Commit 98ea7a5

Browse files
authored
refactor(mklink): Use 'New-Item' instead of 'mklink' (#4690)
1 parent 2644a5f commit 98ea7a5

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
- **depends:** Rewrite 'depends.ps1' ([#4638](https://github.com/ScoopInstaller/Scoop/issues/4638))
3030
- **depends:** Keep bucket in 'Get-Dependency()' ([#4673](https://github.com/ScoopInstaller/Scoop/issues/4673))
31+
- **mklink:** Use 'New-Item' instead of 'mklink' ([#4690](https://github.com/ScoopInstaller/Scoop/issues/4690))
3132

3233
### Builds
3334

lib/install.ps1

+8-8
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ function link_current($versiondir) {
927927
& "$env:COMSPEC" /c rmdir $currentdir
928928
}
929929

930-
& "$env:COMSPEC" /c mklink /j $currentdir $versiondir | out-null
930+
New-Item -Path $currentdir -ItemType Junction -Value $versiondir | Out-Null
931931
attrib $currentdir +R /L
932932
return $currentdir
933933
}
@@ -1154,15 +1154,15 @@ function persist_data($manifest, $original_dir, $persist_dir) {
11541154
if (Test-Path $source) {
11551155
Move-Item -Force $source "$source.original"
11561156
}
1157-
# we don't have persist data in the store, move the source to target, then create link
1157+
# we don't have persist data in the store, move the source to target, then create link
11581158
} elseif (Test-Path $source) {
11591159
# ensure target parent folder exist
11601160
ensure (Split-Path -Path $target) | Out-Null
11611161
Move-Item $source $target
1162-
# we don't have neither source nor target data! we need to crate an empty target,
1163-
# but we can't make a judgement that the data should be a file or directory...
1164-
# so we create a directory by default. to avoid this, use pre_install
1165-
# to create the source file before persisting (DON'T use post_install)
1162+
# we don't have neither source nor target data! we need to crate an empty target,
1163+
# but we can't make a judgement that the data should be a file or directory...
1164+
# so we create a directory by default. to avoid this, use pre_install
1165+
# to create the source file before persisting (DON'T use post_install)
11661166
} else {
11671167
$target = New-Object System.IO.DirectoryInfo($target)
11681168
ensure $target | Out-Null
@@ -1171,11 +1171,11 @@ function persist_data($manifest, $original_dir, $persist_dir) {
11711171
# create link
11721172
if (is_directory $target) {
11731173
# target is a directory, create junction
1174-
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | out-null
1174+
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
11751175
attrib $source +R /L
11761176
} else {
11771177
# target is a file, create hard link
1178-
& "$env:COMSPEC" /c "mklink /h `"$source`" `"$target`"" | out-null
1178+
New-Item -Path $source -ItemType HardLink -Value $target | Out-Null
11791179
}
11801180
}
11811181
}

lib/psmodules.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function install_psmodule($manifest, $dir, $global) {
2626
& "$env:COMSPEC" /c "rmdir `"$linkfrom`""
2727
}
2828

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

3232
function uninstall_psmodule($manifest, $dir, $global) {

0 commit comments

Comments
 (0)