From 0c428391e6976cc4ea94f8552e8ef21d1e87e6ce Mon Sep 17 00:00:00 2001 From: zStruCat Date: Sun, 3 Jul 2022 10:56:36 +0800 Subject: [PATCH 1/7] Add nullity check and alread_in_local_bucket check --- libexec/scoop-import.ps1 | 73 +++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/libexec/scoop-import.ps1 b/libexec/scoop-import.ps1 index bc6a67a60f..e71082f2fd 100644 --- a/libexec/scoop-import.ps1 +++ b/libexec/scoop-import.ps1 @@ -7,6 +7,7 @@ param( $scoopfile ) +. "$PSScriptRoot\..\lib\buckets.ps1" # Get-LocalBucket . "$PSScriptRoot\..\lib\manifest.ps1" $import = $null @@ -21,42 +22,54 @@ if (Test-Path $scoopfile) { if (!$import) { abort 'Input file not a valid JSON.' } -$import.config.PSObject.Properties | ForEach-Object { - set_config $_.Name $_.Value | Out-Null - Write-Host "'$($_.Name)' has been set to '$($_.Value)'" +if ($null -ne $import.config.PSObject.Properties) { + $import.config.PSObject.Properties | ForEach-Object { + set_config $_.Name $_.Value | Out-Null + Write-Host "'$($_.Name)' has been set to '$($_.Value)'" + } } -$import.buckets | ForEach-Object { - add_bucket $_.Name $_.Source | Out-Null - $bucket_names += $_.Name +if ($null -ne $import.buckets){ + $local_buckets = Get-LocalBucket + $import.buckets | ForEach-Object { + if($_.Name -in $local_buckets){ + Write-Host "'$($_.Name)' is already in your local bucket. It won't be added again." + $bucket_names += $_.Name + }else { + add_bucket $_.Name $_.Source + $bucket_names += $_.Name + } + } } -$import.apps | ForEach-Object { - $info = $_.Info -Split ', ' - $global = if ('Global install' -in $info) { - ' --global' - } else { - '' - } - $arch = if ('64bit' -in $info -and '32bit' -eq $def_arch) { - ' --arch 64bit' - } elseif ('32bit' -in $info -and '64bit' -eq $def_arch) { - ' --arch 32bit' - } else { - '' - } +if ($null -ne $import.apps) { + $import.apps | ForEach-Object { + $info = $_.Info -Split ', ' + $global = if ('Global install' -in $info) { + ' --global' + } else { + '' + } + $arch = if ('64bit' -in $info -and '32bit' -eq $def_arch) { + ' --arch 64bit' + } elseif ('32bit' -in $info -and '64bit' -eq $def_arch) { + ' --arch 32bit' + } else { + '' + } - $app = if ($_.Source -in $bucket_names) { - "$($_.Source)/$($_.Name)" - } elseif ($_.Source -eq '') { - "$($_.Name)@$($_.Version)" - } else { - $_.Source - } + $app = if ($_.Source -in $bucket_names) { + "$($_.Source)/$($_.Name)" + } elseif ($_.Source -eq '') { + "$($_.Name)@$($_.Version)" + } else { + $_.Source + } - & "$PSScriptRoot\scoop-install.ps1" $app$global$arch + & "$PSScriptRoot\scoop-install.ps1" $app$global$arch - if ('Held package' -in $info) { - & "$PSScriptRoot\scoop-hold.ps1" $($_.Name)$global + if ('Held package' -in $info) { + & "$PSScriptRoot\scoop-hold.ps1" $($_.Name)$global + } } } From e1f386e9e2559e00ae714e2cf39d992438d31cae Mon Sep 17 00:00:00 2001 From: zStruCat Date: Sun, 3 Jul 2022 11:07:27 +0800 Subject: [PATCH 2/7] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef6cbe17d9..2a8f027e62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014)) ### Bug Fixes +- **scoop-import:** Add nullity check and is-already in bucket check ([#5034](https://github.com/ScoopInstaller/Scoop/pull/5034)) - **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002)), ([#5029](https://github.com/ScoopInstaller/Scoop/issues/5029)) - **decompress:** Handle split RAR archives ([#4994](https://github.com/ScoopInstaller/Scoop/issues/4994)) From 7aef15a268ef0d5818959901e53b572f3e0aea0a Mon Sep 17 00:00:00 2001 From: Rashil Gandhi Date: Wed, 6 Jul 2022 11:45:30 +0530 Subject: [PATCH 3/7] Use foreach instead of ForEach-Object --- libexec/scoop-import.ps1 | 73 +++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/libexec/scoop-import.ps1 b/libexec/scoop-import.ps1 index e71082f2fd..5b485133b2 100644 --- a/libexec/scoop-import.ps1 +++ b/libexec/scoop-import.ps1 @@ -7,7 +7,6 @@ param( $scoopfile ) -. "$PSScriptRoot\..\lib\buckets.ps1" # Get-LocalBucket . "$PSScriptRoot\..\lib\manifest.ps1" $import = $null @@ -22,54 +21,42 @@ if (Test-Path $scoopfile) { if (!$import) { abort 'Input file not a valid JSON.' } -if ($null -ne $import.config.PSObject.Properties) { - $import.config.PSObject.Properties | ForEach-Object { - set_config $_.Name $_.Value | Out-Null - Write-Host "'$($_.Name)' has been set to '$($_.Value)'" - } +foreach ($item in $import.config.PSObject.Properties) { + set_config $item.Name $item.Value | Out-Null + Write-Host "'$($item.Name)' has been set to '$($item.Value)'" } -if ($null -ne $import.buckets){ - $local_buckets = Get-LocalBucket - $import.buckets | ForEach-Object { - if($_.Name -in $local_buckets){ - Write-Host "'$($_.Name)' is already in your local bucket. It won't be added again." - $bucket_names += $_.Name - }else { - add_bucket $_.Name $_.Source - $bucket_names += $_.Name - } - } +foreach ($item in $import.buckets) { + add_bucket $item.Name $item.Source | Out-Null + $bucket_names += $item.Name } -if ($null -ne $import.apps) { - $import.apps | ForEach-Object { - $info = $_.Info -Split ', ' - $global = if ('Global install' -in $info) { - ' --global' - } else { - '' - } - $arch = if ('64bit' -in $info -and '32bit' -eq $def_arch) { - ' --arch 64bit' - } elseif ('32bit' -in $info -and '64bit' -eq $def_arch) { - ' --arch 32bit' - } else { - '' - } +foreach ($item in $import.apps) { + $info = $item.Info -Split ', ' + $global = if ('Global install' -in $info) { + ' --global' + } else { + '' + } + $arch = if ('64bit' -in $info -and '32bit' -eq $def_arch) { + ' --arch 64bit' + } elseif ('32bit' -in $info -and '64bit' -eq $def_arch) { + ' --arch 32bit' + } else { + '' + } - $app = if ($_.Source -in $bucket_names) { - "$($_.Source)/$($_.Name)" - } elseif ($_.Source -eq '') { - "$($_.Name)@$($_.Version)" - } else { - $_.Source - } + $app = if ($item.Source -in $bucket_names) { + "$($item.Source)/$($item.Name)" + } elseif ($item.Source -eq '') { + "$($item.Name)@$($item.Version)" + } else { + $item.Source + } - & "$PSScriptRoot\scoop-install.ps1" $app$global$arch + & "$PSScriptRoot\scoop-install.ps1" $app$global$arch - if ('Held package' -in $info) { - & "$PSScriptRoot\scoop-hold.ps1" $($_.Name)$global - } + if ('Held package' -in $info) { + & "$PSScriptRoot\scoop-hold.ps1" $($item.Name)$global } } From ccf984b8aa38d3c98ef3364b45acb0aab122aef3 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi Date: Wed, 6 Jul 2022 11:52:55 +0530 Subject: [PATCH 4/7] changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a8f027e62..d9b9f95aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,9 @@ - **chore:** Add missing -a/--all param to all commands ([#5004](https://github.com/ScoopInstaller/Scoop/issues/5004)) - **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011)) - **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886)) -- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014)) +- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014), [#5034](https://github.com/ScoopInstaller/Scoop/issues/5034)) ### Bug Fixes -- **scoop-import:** Add nullity check and is-already in bucket check ([#5034](https://github.com/ScoopInstaller/Scoop/pull/5034)) - **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002)), ([#5029](https://github.com/ScoopInstaller/Scoop/issues/5029)) - **decompress:** Handle split RAR archives ([#4994](https://github.com/ScoopInstaller/Scoop/issues/4994)) From a65f84cbceb4a6f1b2ddb59b17feb0e337c95728 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi Date: Wed, 6 Jul 2022 12:08:23 +0530 Subject: [PATCH 5/7] update help --- libexec/scoop-import.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libexec/scoop-import.ps1 b/libexec/scoop-import.ps1 index 5b485133b2..b6a0ba5d6b 100644 --- a/libexec/scoop-import.ps1 +++ b/libexec/scoop-import.ps1 @@ -1,5 +1,7 @@ # Usage: scoop import # 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 param( [Parameter(Mandatory)] From f6ad58fa02bcf9c13a4a69194b322233309bd8ad Mon Sep 17 00:00:00 2001 From: zStruCat Date: Wed, 6 Jul 2022 23:00:55 +0800 Subject: [PATCH 6/7] refine the info and warning when adding an already-added bucket --- lib/buckets.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/buckets.ps1 b/lib/buckets.ps1 index fa3fc8d6c5..83f2627c95 100644 --- a/lib/buckets.ps1 +++ b/lib/buckets.ps1 @@ -120,7 +120,8 @@ function add_bucket($name, $repo) { $dir = Find-BucketDirectory $name -Root if (Test-Path $dir) { - warn "The '$name' bucket already exists. Use 'scoop bucket rm $name' to remove it." + warn "The '$name' bucket already exists locally. It won't be added again." + info "If you want to add the '$name' bucket. You must first use 'scoop bucket rm $name' to remove the already-locally-added namesake." return 2 } From 8834b69dd07e61e67ff81ba234eb635579a013f1 Mon Sep 17 00:00:00 2001 From: zStruCat <98123484+zStruCat@users.noreply.github.com> Date: Thu, 7 Jul 2022 08:38:07 +0800 Subject: [PATCH 7/7] Update lib/buckets.ps1 Make warning clearer Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> --- lib/buckets.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/buckets.ps1 b/lib/buckets.ps1 index 83f2627c95..c22c291220 100644 --- a/lib/buckets.ps1 +++ b/lib/buckets.ps1 @@ -120,8 +120,7 @@ function add_bucket($name, $repo) { $dir = Find-BucketDirectory $name -Root if (Test-Path $dir) { - warn "The '$name' bucket already exists locally. It won't be added again." - info "If you want to add the '$name' bucket. You must first use 'scoop bucket rm $name' to remove the already-locally-added namesake." + warn "The '$name' bucket already exists. To add this bucket again, first remove it by running 'scoop bucket rm $name'." return 2 }