Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Oct 3, 2023

Conversation

HUMORCE
Copy link
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
Member

Add it as fallback, not a replacement?

@HUMORCE
Copy link
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
2 checks passed
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
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
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

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.

None yet

4 participants