Skip to content

fix(core): Use relative path as fallback of $scoopdir#5544

Merged
rashil2000 merged 5 commits intoScoopInstaller:developfrom
HUMORCE:scoop_root_dir
Oct 3, 2023
Merged

fix(core): Use relative path as fallback of $scoopdir#5544
rashil2000 merged 5 commits intoScoopInstaller:developfrom
HUMORCE:scoop_root_dir

Conversation

@HUMORCE
Copy link
Copy Markdown
Member

@HUMORCE HUMORCE commented Jun 18, 2023

Description

Use relative path as fallback of Scoop root directory.

Motivation and Context

Fallback to ~\scoop cause non-standard installations of Scoop to not be recognized properly.

Relates to #5543 #5542 (reply in thread)

How Has This Been Tested?

Before:

PS C:\Users\WDAGUtilityAccount> scoop bucket list
Get-ChildItem : Cannot find path 'C:\Users\WDAGUtilityAccount\scoop\buckets' because it does not exist.
At C:\Users\WDAGUtilityAccount\中文\s p a c e\scoop\apps\scoop\current\lib\buckets.ps1:61 char:62
+ ... eneric.List[String]](Get-ChildItem -Path $bucketsdir -Directory).Name
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\WDAGUt...t\scoop\buckets:String) [Get-ChildItem], ItemNotFound
   Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

WARN  No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket.

After:

PS C:\Users\WDAGUtilityAccount> scoop bucket list

Name     Source                                Updated               Manifests
----     ------                                -------               ---------
main     ~\中文\s p a c e\scoop\buckets\main     6/18/2023 11:29:54 AM      1207
extras   ~\中文\s p a c e\scoop\buckets\extras   6/18/2023 11:29:54 AM      1880
versions ~\中文\s p a c e\scoop\buckets\versions 6/18/2023 11:29:56 AM       425
java     ~\中文\s p a c e\scoop\buckets\java     6/18/2023 11:29:55 AM       253
nuke     ~\中文\s p a c e\scoop\buckets\nuke     6/18/2023 11:29:54 AM       134


PS C:\Users\WDAGUtilityAccount> $env:SCOOP
PS C:\Users\WDAGUtilityAccount> scoop config
PS C:\Users\WDAGUtilityAccount>

Checklist:

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

@niheaven
Copy link
Copy Markdown
Member

Add it as fallback, not a replacement?

@HUMORCE
Copy link
Copy Markdown
Member Author

HUMORCE commented Jun 18, 2023

Add it as fallback, not a replacement?

I was doing like this, but all the fallbacks after it seem redundant. anyway, re-added.

niheaven
niheaven previously approved these changes Jun 27, 2023
@rashil2000 rashil2000 merged commit 6898773 into ScoopInstaller:develop Oct 3, 2023
CrendKing pushed a commit to CrendKing/Scoop that referenced this pull request Oct 3, 2023
…er#5544)

* fix(core): Use relative path as fallback of `$scoopdir`(Scoop root directory)

* typo

* changelog

* re

---------

Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
@r15ch13
Copy link
Copy Markdown
Member

r15ch13 commented Oct 9, 2023

While testing scoop diag I noticed that this will return the wrong path in my dev environment.
The scoop source is located in X:\~projects\~powershell\scoop and this change will set:

ScoopDir     = X:\
CacheDir     = X:\\cache

Before this change it would be set to

ScoopDir     = %USERPROFILE%\scoop
CacheDir     = %USERPROFILE%\scoop\cache

I don't have $env:SCOOP set, because I use my normal Scoop install for testing (~\scoop). Am I the one with the odd setup? 😄

@HUMORCE
Copy link
Copy Markdown
Member Author

HUMORCE commented Oct 9, 2023

The change is based on a standard installation.

  • Switch to standard directory structure
  • Set $env:SCOOP manually before use dev environment

Non-standard dir structure may not be possible to test certain features, functions. e.g.

Scoop/lib/core.ps1

Lines 1396 to 1422 in 3a3f41c

# Load Scoop config
$configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Select-Object -First 1
$configFile = "$configHome\scoop\config.json"
# Check if it's the expected install path for scoop: <root>/apps/scoop/current
$coreRoot = Split-Path $PSScriptRoot
$pathExpected = ($coreRoot -replace '\\','/') -like '*apps/scoop/current*'
if ($pathExpected) {
# Portable config is located in root directory:
# .\current\scoop\apps\<root>\config.json <- a reversed path
# Imagine `<root>/apps/scoop/current/` in a reversed format,
# and the directory tree:
#
# ```
# <root>:
# ├─apps
# ├─buckets
# ├─cache
# ├─persist
# ├─shims
# ├─config.json
# ```
$configPortablePath = fullpath "$coreRoot\..\..\..\config.json"
if (Test-Path $configPortablePath) {
$configFile = $configPortablePath
}
}
$scoopConfig = load_cfg $configFile

@HUMORCE HUMORCE deleted the scoop_root_dir branch August 10, 2025 20:00
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.

4 participants