fix: handle icacls exit code and copy overwrites

This commit is contained in:
Esdras Renan 2025-11-12 10:55:08 -03:00
parent dd57bc9886
commit 4b0bdd7026

View file

@ -642,9 +642,12 @@ if (-not (Test-Path '{target}')) {{ New-Item -ItemType Directory -Force -Path '{
$admins = (New-Object Security.Principal.SecurityIdentifier('S-1-5-32-544')).Translate([Security.Principal.NTAccount]).Value
$localSvc = (New-Object Security.Principal.SecurityIdentifier('S-1-5-19')).Translate([Security.Principal.NTAccount]).Value
takeown /F '{target}' /R /D Y | Out-Null
if ($LASTEXITCODE -ne 0) {{ exit $LASTEXITCODE }}
if ($LASTEXITCODE -ne 0) {{ $take = $LASTEXITCODE }} else {{ $take = 0 }}
icacls '{target}' /grant "${{admins}}":(OI)(CI)F "${{localSvc}}":(OI)(CI)F /T /C | Out-Null
exit $LASTEXITCODE
$ica = $LASTEXITCODE
if (($take -eq 0) -and ($ica -in 0,1)) {{ exit 0 }}
if ($ica -ne 0) {{ exit $ica }}
exit $take
"#
);
run_powershell_elevated(&script)