Skip to content

Commit 4047d69

Browse files
authored
perf(install): Avoid checking all files for unlink persisted data (#4681)
1 parent 40b2d95 commit 4047d69

6 files changed

Lines changed: 28 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
- **scoop-update:** Skip updating non git buckets ([#4670](https://github.com/ScoopInstaller/Scoop/issues/4670), [#4672](https://github.com/ScoopInstaller/Scoop/issues/4672))
3737
- **scoop-bucket:** Check for git before running command ([#4756](https://github.com/ScoopInstaller/Scoop/issues/4756))
3838

39+
### Performance Improvements
40+
41+
- **uninstall:** Avoid checking all files for unlinking persisted data ([#4681](https://github.com/ScoopInstaller/Scoop/issues/4681))
42+
3943
### Code Refactoring
4044

4145
- **depends:** Rewrite 'depends.ps1' ([#4638](https://github.com/ScoopInstaller/Scoop/issues/4638), [#4673](https://github.com/ScoopInstaller/Scoop/issues/4673))

lib/core.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ function shim($path, $global, $name, $arg) {
720720
} else {
721721
warn_on_overwrite "$shim.cmd" $path
722722
# find path to Git's bash so that batch scripts can run bash scripts
723-
$gitdir = (Get-Item (Get-Command git -ErrorAction:Stop).Source -ErrorAction:Stop).Directory.Parent
723+
$gitdir = (Get-Item (Get-Command git -CommandType:Application -ErrorAction:Stop).Source -ErrorAction:Stop).Directory.Parent
724724
if ($gitdir.FullName -imatch 'mingw') {
725725
$gitdir = $gitdir.Parent
726726
}

lib/install.ps1

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ function persist_data($manifest, $original_dir, $persist_dir) {
11771177
# ensure target parent folder exist
11781178
ensure (Split-Path -Path $target) | Out-Null
11791179
Move-Item $source $target
1180-
# we don't have neither source nor target data! we need to crate an empty target,
1180+
# we don't have neither source nor target data! we need to create an empty target,
11811181
# but we can't make a judgement that the data should be a file or directory...
11821182
# so we create a directory by default. to avoid this, use pre_install
11831183
# to create the source file before persisting (DON'T use post_install)
@@ -1199,21 +1199,25 @@ function persist_data($manifest, $original_dir, $persist_dir) {
11991199
}
12001200
}
12011201

1202-
function unlink_persist_data($dir) {
1202+
function unlink_persist_data($manifest, $dir) {
1203+
$persist = $manifest.persist
12031204
# unlink all junction / hard link in the directory
1204-
Get-ChildItem -Recurse $dir | ForEach-Object {
1205-
$file = $_
1206-
if ($null -ne $file.LinkType) {
1207-
$filepath = $file.FullName
1208-
# directory (junction)
1209-
if ($file -is [System.IO.DirectoryInfo]) {
1210-
# remove read-only attribute on the link
1211-
attrib -R /L $filepath
1212-
# remove the junction
1213-
Remove-Item -Path $filepath -Recurse -Force -ErrorAction SilentlyContinue
1214-
} else {
1215-
# remove the hard link
1216-
Remove-Item -Path $filepath -Force -ErrorAction SilentlyContinue
1205+
if ($persist) {
1206+
@($persist) | ForEach-Object {
1207+
$source, $null = persist_def $_
1208+
$source = Get-Item "$dir\$source"
1209+
if ($source.LinkType) {
1210+
$source_path = $source.FullName
1211+
# directory (junction)
1212+
if ($source -is [System.IO.DirectoryInfo]) {
1213+
# remove read-only attribute on the link
1214+
attrib -R /L $source_path
1215+
# remove the junction
1216+
Remove-Item -Path $source_path -Recurse -Force -ErrorAction SilentlyContinue
1217+
} else {
1218+
# remove the hard link
1219+
Remove-Item -Path $source_path -Force -ErrorAction SilentlyContinue
1220+
}
12171221
}
12181222
}
12191223
}

libexec/scoop-cleanup.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function cleanup($app, $global, $verbose, $cache) {
4949
Write-Host " $version" -NoNewline
5050
$dir = versiondir $app $version $global
5151
# unlink all potential old link before doing recursive Remove-Item
52-
unlink_persist_data $dir
52+
unlink_persist_data $manifest $dir
5353
Remove-Item $dir -ErrorAction Stop -Recurse -Force
5454
}
5555
$leftVersions = Get-ChildItem $appDir

libexec/scoop-reset.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ $apps | ForEach-Object {
8282
env_add_path $manifest $dir $global $architecture
8383
env_set $manifest $dir $global $architecture
8484
# unlink all potential old link before re-persisting
85-
unlink_persist_data $original_dir
85+
unlink_persist_data $manifest $original_dir
8686
persist_data $manifest $original_dir $persist_dir
8787
persist_permission $manifest $global
8888
}

libexec/scoop-uninstall.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if (!$apps) { exit 0 }
9191

9292
try {
9393
# unlink all potential old link before doing recursive Remove-Item
94-
unlink_persist_data $dir
94+
unlink_persist_data $manifest $dir
9595
Remove-Item $dir -Recurse -Force -ErrorAction Stop
9696
} catch {
9797
if (Test-Path $dir) {
@@ -107,7 +107,7 @@ if (!$apps) { exit 0 }
107107
$dir = versiondir $app $version $global
108108
try {
109109
# unlink all potential old link before doing recursive Remove-Item
110-
unlink_persist_data $dir
110+
unlink_persist_data $manifest $dir
111111
Remove-Item $dir -Recurse -Force -ErrorAction Stop
112112
} catch {
113113
error "Couldn't remove '$(friendly_path $dir)'; it may be in use."

0 commit comments

Comments
 (0)