Skip to content

Commit

Permalink
refactor(mklink): Use 'New-Item' instead of 'mklink' (#4690)
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven authored Jan 25, 2022
1 parent 2644a5f commit 98ea7a5
Show file tree
Hide file tree
Showing 3 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 @@ -28,6 +28,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

0 comments on commit 98ea7a5

Please sign in to comment.