fix!: validate directories before install - #135
Conversation
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
28db0df to
2e5efa4
Compare
Summary by CodeRabbit
Walkthrough
ChangesInstallation validation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.) Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7e9fb56e-fff1-4947-812b-1ad7b02d2889
📒 Files selected for processing (1)
install.ps1
Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
install.ps1 (1)
144-145:⚠️ Potential issue | 🟡 MinorPreserve literal, fail-closed directory validation.
Test-Path -Path "$DIR\*"interprets the path as a wildcard. It can miss hidden-only children, and path names containing wildcard characters can resolve incorrectly. The check can therefore allow installation into a non-empty directory. PowerShell documents this wildcard behavior, and hidden-item misses are documented in the PowerShell issue tracker. (learn.microsoft.com)Use
-LiteralPathfor the directory check, enumerate withGet-ChildItem -Force, and treat enumeration errors as validation failures. This is the same unresolved issue reported previously.$root = Join-Path $env:TEMP ("scoop-path-check-" + [guid]::NewGuid()) $hiddenDir = Join-Path $root 'hidden-only' $specialDir = Join-Path $root 'name[1]' [System.IO.Directory]::CreateDirectory($hiddenDir) | Out-Null [System.IO.Directory]::CreateDirectory($specialDir) | Out-Null $hiddenFile = Join-Path $hiddenDir '.keep' [System.IO.File]::WriteAllText($hiddenFile, '') [System.IO.File]::SetAttributes($hiddenFile, [System.IO.FileAttributes]::Hidden) [System.IO.File]::WriteAllText((Join-Path $specialDir 'keep'), '') try { [pscustomobject]@{ HiddenOnly_TestPath = Test-Path -Path "$hiddenDir\*" HiddenOnly_ForceCount = @(Get-ChildItem -LiteralPath $hiddenDir -Force).Count WildcardName_TestPath = Test-Path -Path "$specialDir\*" WildcardName_LiteralCount = @(Get-ChildItem -LiteralPath $specialDir -Force).Count } } finally { [System.IO.Directory]::Delete($root, $true) }Also applies to: 152-153
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3a41dc48-1fdf-419c-9cdf-a0a3e70dca38
📒 Files selected for processing (1)
install.ps1
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c9935c28-d9cc-4413-b9e1-a6ff41f9ae06
📒 Files selected for processing (2)
install.ps1test/install.Tests.ps1
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.
An alternative implementation of #76, relates to #60
This COULD be a BREAKING CHANGE, as the behavior has changed. Before this downstreams may run the installer to install Scoop into a directory that's non-empty, and with this PR it'll fail. But it's certain a bad idea to install Scoop into a non-empty directory because serious problems will arise, we should not support such installation.
Closes ScoopInstaller/Scoop#6655