fleet/pkg/file/testdata/scripts/remove_exe.ps1.golden
Roberto Dip d383876a3c
fix issues installing software in windows (#19048)
for #19039 and #19041 this:

- fixes the install/remove scripts to read the env variable the proper
way
- truncates output before storing in the databse in case its longer than
MySQL's TEXT size

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-05-15 19:39:42 -03:00

14 lines
706 B
Text

$exeFilePath = "${env:INSTALLER_PATH}"
# extract the name of the executable to use as the sub-directory name
$exeName = [System.IO.Path]::GetFileName($exeFilePath)
$subDir = [System.IO.Path]::GetFileNameWithoutExtension($exeFilePath)
# determine the correct Program Files directory based on OS architecture
$destinationPath = Join-Path -Path $env:ProgramFiles -ChildPath $subDir
$destinationExePath = Join-Path -Path $destinationPath -ChildPath $exeName
# remove only the exe file, while at runtime other files could have been
# created in this folder, this is a naive approach to prevent forcing us to
# remove important folders by crafting a malicious file name.
Remove-Item -Path $destinationExePath