From 6181058c3ea2cf53b5f6c41d11245f5ab5263dcf Mon Sep 17 00:00:00 2001 From: flodavid Date: Sun, 21 Jul 2024 16:02:38 +0200 Subject: [PATCH] feat(persist): Allow custom persist directories - Priority order for local apps: - `SCOOP_PERSIST` env variable, `PERSIST_PATH` config, default value - Priority order for global apps - `SCOOP_PERSIST_GLOBAL` env variable, `GLOBAL_PERSIST_PATH` config, default value --- lib/core.ps1 | 9 ++++++++- libexec/scoop-config.ps1 | 6 ++++++ libexec/scoop-export.ps1 | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 193a8c0020..728c2d23db 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -402,7 +402,7 @@ function currentdir($app, $global) { "$(appdir $app $global)\$version" } -function persistdir($app, $global) { "$(basedir $global)\persist\$app" } +function persistdir($app, $global) { if($global) { return "$globalpersistdir\$app" } "$persistdir\$app" } function usermanifestsdir { "$(basedir)\workspace" } function usermanifest($app) { "$(usermanifestsdir)\$app.json" } function cache_path($app, $version, $url) { @@ -1464,6 +1464,13 @@ $globaldir = $env:SCOOP_GLOBAL, (get_config GLOBAL_PATH), "$([System.Environment # Use at your own risk. $cachedir = $env:SCOOP_CACHE, (get_config CACHE_PATH), "$scoopdir\cache" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath +# Scoop persist directory +# Note: Setting the SCOOP_PERSIST environment variable to use a shared directory +# may cause problems depending on the app. +# Use at your own risk. +$persistdir = $env:SCOOP_PERSIST, (get_config PERSIST_PATH), "$scoopdir\persist" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath +$globalpersistdir = $env:SCOOP_PERSIST_GLOBAL, (get_config GLOBAL_PERSIST_PATH), "$globaldir\persist" | Where-Object { $_ } | Select-Object -First 1 | Get-AbsolutePath + # Scoop apps' PATH Environment Variable $scoopPathEnvVar = switch (get_config USE_ISOLATED_PATH) { { $_ -is [string] } { $_.ToUpperInvariant() } diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index 6007bd6434..7c9d90af19 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -83,6 +83,12 @@ # cache_path: # For downloads, defaults to 'cache' folder under Scoop root directory. # +# persist_path: +# Directories persisted during installation of new versions , defaults to 'persist' folder under Scoop root directory. +# +# global_persist_path: +# Directories persisted during installation of new versions , defaults to 'persist' folder under Scoop global directory. +# # gh_token: # GitHub API token used to make authenticated requests. # This is essential for checkver and similar functions to run without diff --git a/libexec/scoop-export.ps1 b/libexec/scoop-export.ps1 index 8eff8db0c5..8be7c8baef 100644 --- a/libexec/scoop-export.ps1 +++ b/libexec/scoop-export.ps1 @@ -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', 'root_path', 'global_path', 'cache_path', 'persist_path', 'global_persist_path', 'alias') { $export.config.PSObject.Properties.Remove($prop) } }