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

Fixed issues when scoop is installed to a separate directory from the apps folder (2nd PR since I made some mistakes) #6001

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- **scoop-search:** Use SQLite for caching apps to speed up local search ([#5851](https://github.com/ScoopInstaller/Scoop/issues/5851), [#5918](https://github.com/ScoopInstaller/Scoop/issues/5918), [#5946](https://github.com/ScoopInstaller/Scoop/issues/5946), [#5949](https://github.com/ScoopInstaller/Scoop/issues/5949), [#5955](https://github.com/ScoopInstaller/Scoop/issues/5955), [#5966](https://github.com/ScoopInstaller/Scoop/issues/5966), [#5967](https://github.com/ScoopInstaller/Scoop/issues/5967), [#5981](https://github.com/ScoopInstaller/Scoop/issues/5981))
- **core:** New cache filename format ([#5929](https://github.com/ScoopInstaller/Scoop/issues/5929))
- **core** Scoop is now able to be installed in a directory independent of the global and local apps directory
- **install:** Added the ability to install specific version of app from URL/file link ([#5988](https://github.com/ScoopInstaller/Scoop/issues/5988))

### Bug Fixes
Expand Down
2 changes: 2 additions & 0 deletions bin/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ if ($errors) {

if ($purge) {
rm_dir $scoopdir
rm_dir $localdir
if ($global) { rm_dir $globaldir }
} else {
keep_onlypersist $scoopdir
keep_onlypersist $localdir
if ($global) { keep_onlypersist $globaldir }
}

Expand Down
59 changes: 26 additions & 33 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function Complete-ConfigChange {
$Value.ToUpperInvariant()
}
info "Turn on Scoop isolated path ('$newPathEnvVar')... This may take a while, please wait."
$movedPath = Remove-Path -Path "$scoopdir\apps\*" -TargetEnvVar $currPathEnvVar -Quiet -PassThru
$movedPath = Remove-Path -Path "$localdir\apps\*" -TargetEnvVar $currPathEnvVar -Quiet -PassThru
if ($movedPath) {
Add-Path -Path $movedPath -TargetEnvVar $newPathEnvVar -Quiet
Add-Path -Path ('%' + $newPathEnvVar + '%') -Quiet
Expand Down Expand Up @@ -386,7 +386,7 @@ function filesize($length) {
}

# dirs
function basedir($global) { if($global) { return $globaldir } $scoopdir }
function basedir($global) { if($global) { return $globaldir } $localdir }
function appsdir($global) { "$(basedir $global)\apps" }
function shimdir($global) { "$(basedir $global)\shims" }
function modulesdir($global) { "$(basedir $global)\modules" }
Expand Down Expand Up @@ -1081,10 +1081,10 @@ function shim($path, $global, $name, $arg) {
function get_shim_path() {
$shim_version = get_config SHIM 'kiennq'
$shim_path = switch ($shim_version) {
'scoopcs' { "$(versiondir 'scoop' 'current')\supporting\shims\scoopcs\shim.exe" }
'71' { "$(versiondir 'scoop' 'current')\supporting\shims\71\shim.exe" }
'kiennq' { "$(versiondir 'scoop' 'current')\supporting\shims\kiennq\shim.exe" }
'default' { "$(versiondir 'scoop' 'current')\supporting\shims\scoopcs\shim.exe" }
'scoopcs' { "$($scoopdir)\apps\scoop\current\supporting\shims\scoopcs\shim.exe" }
'71' { "$($scoopdir)\apps\scoop\current\supporting\shims\71\shim.exe" }
'kiennq' { "$($scoopdir)\apps\scoop\current\supporting\shims\kiennq\shim.exe" }
'default' { "$($scoopdir)\apps\scoop\current\supporting\shims\scoopcs\shim.exe" }
default { warn "Unknown shim version: '$shim_version'" }
}
return $shim_path
Expand Down Expand Up @@ -1401,6 +1401,20 @@ function Out-UTF8File {
}
}

function getOldRootPath() {
$configRootPath = (get_config ROOT_PATH)
if ($configRootPath -ne $null) {
(set_config ROOT_PATH $null)
(set_config LOCAL_PATH $configRootPath)
return $configRootPath
}
$userProfileScoop = "$([System.Environment]::GetFolderPath('UserProfile'))\scoop"
if (Test-Path -Path $userProfileScoop) {
return $userProfileScoop
}
return $null
}

##################
# Core Bootstrap #
##################
Expand All @@ -1409,36 +1423,15 @@ function Out-UTF8File {
# for all communication with api.github.com
Optimize-SecurityProtocol

# Scoop root directory
$scoopdir = "$PSScriptRoot\..\..\..\.."

# 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 = Get-AbsolutePath "$coreRoot\..\..\..\config.json"
if (Test-Path $configPortablePath) {
$configFile = $configPortablePath
}
}
$configFile = "$scoopdir\config.json"
$scoopConfig = load_cfg $configFile

# Scoop root directory
$scoopdir = $env:SCOOP, (get_config ROOT_PATH), "$PSScriptRoot\..\..\..\..", "$([System.Environment]::GetFolderPath('UserProfile'))\scoop" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath
# Scoop local directory
$localdir = $env:SCOOP_LOCAL, (get_config LOCAL_PATH), "$([System.Environment]::GetFolderPath('LocalApplicationData'))\scoop", (getOldRootPath) | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath

# Scoop global apps directory
$globaldir = $env:SCOOP_GLOBAL, (get_config GLOBAL_PATH), "$([System.Environment]::GetFolderPath('CommonApplicationData'))\scoop" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath
Expand Down
2 changes: 1 addition & 1 deletion lib/diagnostic.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function check_windows_defender($global) {
if ((Get-MpPreference).DisableRealtimeMonitoring) { return $true }
if ($defender -and $defender.Status) {
if ($defender.Status -eq [System.ServiceProcess.ServiceControllerStatus]::Running) {
$installPath = $scoopdir;
$installPath = $localdir;
if ($global) { $installPath = $globaldir; }

$exclusionPath = (Get-MpPreference).ExclusionPath
Expand Down
8 changes: 4 additions & 4 deletions libexec/scoop-checkup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ if (!(Test-HelperInstalled -Helper Dark)) {

$globaldir = New-Object System.IO.DriveInfo($globaldir)
if ($globaldir.DriveFormat -ne 'NTFS') {
error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP_GLOBAL or 'global_path' variable in '~/.config/scoop/config.json' to another Drive."
error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP_GLOBAL or 'global_path' variable in '$scoopdir/config.json' to another Drive."
$issues++
}

$scoopdir = New-Object System.IO.DriveInfo($scoopdir)
if ($scoopdir.DriveFormat -ne 'NTFS') {
error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP or 'root_path' variable in '~/.config/scoop/config.json' to another Drive."
$localdir = New-Object System.IO.DriveInfo($localdir)
if ($localdir.DriveFormat -ne 'NTFS') {
error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP_LOCAL or 'local_path' variable in '$scoopdir/config.json' to another Drive."
$issues++
}

Expand Down
4 changes: 2 additions & 2 deletions libexec/scoop-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
# shim: kiennq|scoopcs|71
# Choose scoop shim build.
#
# root_path: $Env:UserProfile\scoop
# Path to Scoop root directory.
# local_path: $Env:LocalAppData\scoop
# Path to Scoop root directory for local apps.
#
# global_path: $Env:ProgramData\scoop
# Path to Scoop root directory for global apps.
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-export.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $export = @{}
if ($args[0] -eq '-c' -or $args[0] -eq '--config') {
$export.config = $scoopConfig
# Remove machine-specific properties
foreach ($prop in 'last_update', 'root_path', 'global_path', 'cache_path', 'alias') {
foreach ($prop in 'last_update', 'local_path', 'global_path', 'cache_path', 'alias') {
$export.config.PSObject.Properties.Remove($prop)
}
}
Expand Down