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

Add support for resetting of apps to be imported #5572

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 @@ -2,6 +2,7 @@

### Features

- **scoop-import:** Add support for resetting of apps to be imported ([#5525](https://github.com/ScoopInstaller/Scoop/issues/5525))
- **scoop-update:** Add support for parallel syncing buckets in PowerShell 7 and improve output ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122))
- **bucket:** Switch nirsoft bucket to ScoopInstaller/Nirsoft ([#5328](https://github.com/ScoopInstaller/Scoop/issues/5328))
- **config:** Support portable config file ([#5369](https://github.com/ScoopInstaller/Scoop/issues/5369))
Expand Down
20 changes: 13 additions & 7 deletions libexec/scoop-import.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Usage: scoop import <path/url to scoopfile.json>
# Usage: scoop import <path/url to scoopfile.json> [options]
# Summary: Imports apps, buckets and configs from a Scoopfile in JSON format
# Help: To replicate a Scoop installation from a file stored on Desktop, run
# scoop import Desktop\scoopfile.json
#
# Options:
# -r, --reset Reset the app after installation

param(
[Parameter(Mandatory)]
[String]
$scoopfile
)

. "$PSScriptRoot\..\lib\getopt.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"

$opt, $scoopfile, $err = getopt $args 'r' 'reset'
if ($err) { "scoop import: $err"; exit 1 }

$reset = $opt.r -or $opt.reset
$import = $null
$bucket_names = @()
$def_arch = Get-DefaultArchitecture
Expand Down Expand Up @@ -59,6 +61,10 @@ foreach ($item in $import.apps) {

& "$PSScriptRoot\scoop-install.ps1" $app @instArgs

if ($reset) {
& "$PSScriptRoot\scoop-reset.ps1" $app
}
Comment on lines +64 to +66
Copy link
Member

Choose a reason for hiding this comment

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

It should not be necessary, because juntion/shims/shorts/etc. of apps is point the latest version when update app.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe it should not, but it is. As I described in the issue #5525 if install different versions of the same app, no install or update command gives you what you want.

Example: I have the apps python310 and python311 out of the versions bucket installed. python311 was the last one and so the shim python.exe points to that of python311. If I now import a scoopfile.json refering to python310, nothing is changed during import. I end up with the wrong python.exe in the PATH. Therefore the reset argument.

Copy link
Member

Choose a reason for hiding this comment

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

This happens after both python310 and python311 have been installed already, then the import operation is performed right?

Copy link
Author

Choose a reason for hiding this comment

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

Exactly.

Copy link
Member

Choose a reason for hiding this comment

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

@xxthunder technically, this is also not required. To see what I mean:

Scoop/lib/install.ps1

Lines 58 to 66 in 6cdcc75

create_shims $manifest $dir $global $architecture
create_startmenu_shortcuts $manifest $dir $global $architecture
install_psmodule $manifest $dir $global
env_add_path $manifest $dir $global $architecture
env_set $manifest $dir $global $architecture
# persist data
persist_data $manifest $original_dir $persist_dir
persist_permission $manifest $global

The functions that scoop-reset will run (see below) have already been run by scoop-install (see above).

create_shims $manifest $dir $global $architecture
create_startmenu_shortcuts $manifest $dir $global $architecture
env_add_path $manifest $dir $global $architecture
env_set $manifest $dir $global $architecture
# unlink all potential old link before re-persisting
unlink_persist_data $manifest $original_dir
persist_data $manifest $original_dir $persist_dir
persist_permission $manifest $global

Copy link
Author

Choose a reason for hiding this comment

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

@rashil2000 @HUMORCE I think this is not true. I want the reset no matter what is already installed. So if I import with, e.g., cmake version 3.24 in my scoopfile.json and cmake 3.24 and 3.26 both already installed and p3.26 was installed the last time. Then the shim cmake points to cmake 3.26. Now I can import my scoopfile as often as I want, nothing will be installed because 3.24 is already installed and nothing will be resetted. So the shim cmake points to cmake 3.26. Exactly this my problem with scoop import. My option --reset solves this.


if ('Held package' -in $info) {
& "$PSScriptRoot\scoop-hold.ps1" $item.Name @holdArgs
}
Expand Down