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 force option to win psrepository copy #599

Open
wants to merge 3 commits into
base: main
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
29 changes: 19 additions & 10 deletions plugins/modules/win_psrepository_copy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ $spec = @{
'NetworkService'
)
}
force = @{
type = 'bool'
default = $false
}
}
}

Expand Down Expand Up @@ -206,17 +210,22 @@ foreach ($user in $profiles) {
$cur_repos = @{}
}

$new_repos = $cur_repos.Clone()
$updated = $false

$src_repos.Keys |
Select-Wildcard -Include $module.Params.name -Exclude $module.Params.exclude |
ForEach-Object -Process {
# explicit scope used inside ForEach-Object to satisfy lint (PSUseDeclaredVarsMoreThanAssignment)
# see https://github.com/PowerShell/PSScriptAnalyzer/issues/827
$Script:updated = $true
$Script:new_repos[$_] = $Script:src_repos[$_]
}
if ($module.Params.force) {
$new_repos = $src_repos.Clone()
$updated = $true
}
else {
$new_repos = $cur_repos.Clone()
$src_repos.Keys |
Select-Wildcard -Include $module.Params.name -Exclude $module.Params.exclude |
ForEach-Object -Process {
# explicit scope used inside ForEach-Object to satisfy lint (PSUseDeclaredVarsMoreThanAssignment)
# see https://github.com/PowerShell/PSScriptAnalyzer/issues/827
$Script:updated = $true
$Script:new_repos[$_] = $Script:src_repos[$_]
}
}

$module.Diff.before[$username] = $cur_repos
$module.Diff.after[$username] = $new_repos
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/win_psrepository_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
- systemprofile
- LocalService
- NetworkService
force:
description:
- If C(True), this deletes repositories that are not present in the source.
type: bool
default: False
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to include the version when this new option was first present in which will be 2.4.0.

Suggested change
default: False
default: False
version_added: 2.4.0

notes:
- Does not require the C(PowerShellGet) module or any other external dependencies.
- User profiles are loaded from the registry. If a given path does not exist (like if the profile directory was deleted), it is silently skipped.
Expand Down
Loading