Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,8 @@ function Out-UTF8File {
Optimize-SecurityProtocol

# Load Scoop config
$configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Select-Object -First 1
$legacyConfig = if (Test-Path "$env:USERPROFILE\.config") { "$env:USERPROFILE\.config" }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

$legacyConfig checks directory existence but the path semantics have shifted.

The legacy path "$env:USERPROFILE\.config" is a directory, while the new persist path on Line 1264 ("$PSScriptRoot\..\..\..\..\persist") is also a directory — both used as a config home prefix for "$configHome\scoop\config.json". However, the legacy .config directory is validated with Test-Path while the persist path is not. A non-existent persist directory would still be selected as the fallback, which may be intentional (config will be created there), but it means the legacy config is only preferred if the directory exists, not if the config file inside it exists.

If a user has an empty ~\.config directory (common on Windows with cross-platform tools) but no ~\.config\scoop\config.json, this will incorrectly select the legacy path over persist, and config loading will silently return $null.

Consider checking for the actual config file instead:

Proposed fix
-$legacyConfig = if (Test-Path "$env:USERPROFILE\.config") { "$env:USERPROFILE\.config" }
+$legacyConfig = if (Test-Path "$env:USERPROFILE\.config\scoop\config.json") { "$env:USERPROFILE\.config" }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$legacyConfig = if (Test-Path "$env:USERPROFILE\.config") { "$env:USERPROFILE\.config" }
$legacyConfig = if (Test-Path "$env:USERPROFILE\.config\scoop\config.json") { "$env:USERPROFILE\.config" }
🧰 Tools
🪛 PSScriptAnalyzer (1.23.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'core.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
In `@lib/core.ps1` at line 1263, The current logic sets $legacyConfig by testing
the existence of the directory "$env:USERPROFILE\.config" which prefers the
legacy directory even when the actual config file
"$env:USERPROFILE\.config\scoop\config.json" is missing; update the check so
$legacyConfig points to the actual config file path (e.g., compose the full path
to "scoop\config.json" under $env:USERPROFILE\.config) and use Test-Path against
that file; similarly ensure $configHome selection logic treats the persist path
and legacy file consistently (check for config file existence rather than just
directory) so loading returns the real config path or falls back to persist when
the file is absent.

$configHome = $env:XDG_CONFIG_HOME, $legacyConfig, "$PSScriptRoot\..\..\..\..\persist" | Select-Object -First 1
$configFile = "$configHome\scoop\config.json"
Comment on lines +1263 to 1265
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: $configHome will be $null when $env:XDG_CONFIG_HOME is unset.

Select-Object -First 1 picks the first array element regardless of whether it's $null. Since most users won't have XDG_CONFIG_HOME set, $configHome resolves to $null and $configFile becomes "\scoop\config.json" (a relative path from the filesystem root), breaking config loading entirely.

Follow the existing pattern used on Line 1292 for $scoopdir — filter out falsy values first:

Proposed fix
-$configHome = $env:XDG_CONFIG_HOME, $legacyConfig, "$PSScriptRoot\..\..\..\..\persist" | Select-Object -First 1
+$configHome = $env:XDG_CONFIG_HOME, $legacyConfig, "$PSScriptRoot\..\..\..\..\persist" | Where-Object { $_ } | Select-Object -First 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$legacyConfig = if (Test-Path "$env:USERPROFILE\.config") { "$env:USERPROFILE\.config" }
$configHome = $env:XDG_CONFIG_HOME, $legacyConfig, "$PSScriptRoot\..\..\..\..\persist" | Select-Object -First 1
$configFile = "$configHome\scoop\config.json"
$legacyConfig = if (Test-Path "$env:USERPROFILE\.config") { "$env:USERPROFILE\.config" }
$configHome = $env:XDG_CONFIG_HOME, $legacyConfig, "$PSScriptRoot\..\..\..\..\persist" | Where-Object { $_ } | Select-Object -First 1
$configFile = "$configHome\scoop\config.json"
🧰 Tools
🪛 PSScriptAnalyzer (1.23.0)

[warning] Missing BOM encoding for non-ASCII encoded file 'core.ps1'

(PSUseBOMForUnicodeEncodedFile)

🤖 Prompt for AI Agents
In `@lib/core.ps1` around lines 1263 - 1265, $configHome can become $null because
Select-Object -First 1 returns the first element even if it's $null; update the
assignment for $configHome (which is used to build $configFile) to filter out
empty/null/falsy values before selecting the first candidate (follow the same
pattern used for $scoopdir): build the candidate list including
$env:XDG_CONFIG_HOME, $legacyConfig, and the fallback, pipe it through a
Where-Object filter that removes empty/null entries, then Select-Object -First 1
so $configHome is never set to $null when XDG_CONFIG_HOME is unset.

# Check if it's the expected install path for scoop: <root>/apps/scoop/current
$coreRoot = Split-Path $PSScriptRoot
Expand Down