Skip to content

move default config file from userprofile\.config to scoop\persist - Update core.ps1#6600

Open
29039 wants to merge 1 commit intoScoopInstaller:masterfrom
29039:patch-1
Open

move default config file from userprofile\.config to scoop\persist - Update core.ps1#6600
29039 wants to merge 1 commit intoScoopInstaller:masterfrom
29039:patch-1

Conversation

@29039
Copy link
Copy Markdown

@29039 29039 commented Feb 13, 2026

Description

dumping a .config folder in the root user profile is annoying, so I propose moving it to be in scoop\persist\scoop to be consistent with other scoop apps

Motivation and Context

Annoyance

Companion to ScoopInstaller/Install#126

How Has This Been Tested?

tested on my PC works fine
tested to still accept .config as priority if it already exists

Checklist:

  • [ x] I have read the Contributing Guide.
  • I have ensured that I am targeting the develop branch.
  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.
  • I have added an entry in the CHANGELOG.

Sorry am noob

Summary by CodeRabbit

  • Chores
    • Enhanced configuration loading to intelligently search multiple paths including legacy and portable configurations. System now checks multiple standard locations in priority order while maintaining full backward compatibility with existing setups, ensuring configurations are correctly located regardless of user environment.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 13, 2026

Walkthrough

Introduces legacy config handling to Scoop's config loading system by adding XDG_CONFIG_HOME, legacyConfig, and persist-based path search order. Adjusts config file resolution to use the new configHome-derived path while preserving portable-config behavior through portable path detection.

Changes

Cohort / File(s) Summary
Config Loading Enhancement
lib/core.ps1
Added legacy config path support and expanded config home search order to include XDG_CONFIG_HOME, legacyConfig, and persist-based paths; updated configFile resolution logic while preserving portable-config behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through config paths so grand,
Legacy tales and XDG at hand,
Portable paths preserved with care,
New search order—precedence everywhere! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: relocating the default config file from userprofile\.config to scoop\persist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@lib/core.ps1`:
- 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.
- Around line 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.
🧹 Nitpick comments (1)
lib/core.ps1 (1)

1264-1264: The persist fallback path is not resolved to an absolute path.

"$PSScriptRoot\..\..\..\..\persist" remains a relative-style path with .. segments. Other path variables in this file (e.g., $scoopdir on Line 1292) are piped through Get-AbsolutePath to normalize them. Since $configFile is derived from $configHome and later used in file I/O (load_cfg, Out-UTF8File), leaving it un-normalized could cause subtle issues with path comparisons or display.

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

Comment thread lib/core.ps1

# 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.

Comment thread lib/core.ps1
Comment on lines +1263 to 1265
$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"
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.

@29039
Copy link
Copy Markdown
Author

29039 commented Feb 13, 2026

There are documentation considerations in the following files but maybe it would be excessive to be doing pull requests for each one:

libexec/scoop-checkup.ps1

libexec/scoop-config.ps1

.github/ISSUE_TEMPLATE/Bug_report.md

Also I think that the coderabbit analysis is wrong - | Select-Object -First 1 skips over the null objects, that is how it was before, and also tested this to be the case.

@abgox
Copy link
Copy Markdown

abgox commented Mar 12, 2026

  • Scoop already supports portable configuration files.
  • You just need to move config.json into the root directory of scoop.
  • However, It can be even better: When installing scoop, directly create config.json in the root directory of scoop.
  • See feat: use portable config Install#119

@29039
Copy link
Copy Markdown
Author

29039 commented Mar 12, 2026

Oh great! Can we please make this the default as to not litter the home directory with extra folders which don't serve much purpose?

To be honest, I already find it quite dubious that Scoop by default I installed to ~\scoop rather than %LocalAppData%\scoop like any other user app would do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants