-
Notifications
You must be signed in to change notification settings - Fork 0
MSI: Update uninstall scripts #3
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
Changes from all commits
b2d2025
81a75b4
3300636
a813e17
d64e6ab
0f4d68d
d64a807
c3d51fd
d9fa4f8
1d40e95
f39a787
60f85bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,53 @@ | ||
| set "INSTDIR=%cd%" | ||
| @echo {{ 'on' if add_debug else 'off' }} | ||
| setlocal | ||
|
|
||
| {%- macro error_block(message, code) -%} | ||
| echo [ERROR] {{ message }} | ||
| {%- if add_debug %} | ||
| >> "%LOG%" echo [ERROR] {{ message }} | ||
| {%- endif %} | ||
| exit /b {{ code }} | ||
| {%- endmacro -%} | ||
|
|
||
| rem Assign INSTDIR and normalize the path | ||
| set "INSTDIR=%~dp0.." | ||
| for %%I in ("%INSTDIR%") do set "INSTDIR=%%~fI" | ||
|
|
||
| set "BASE_PATH=%INSTDIR%\base" | ||
| set "PREFIX=%BASE_PATH%" | ||
| set "CONDA_EXE=%INSTDIR%\{{ conda_exe_name }}" | ||
| set "PAYLOAD_TAR=%INSTDIR%\{{ archive_name }}" | ||
|
|
||
| {%- if add_debug %} | ||
| rem Get the name of the install directory | ||
| for %%I in ("%INSTDIR%") do set "APPNAME=%%~nxI" | ||
| set "LOG=%TEMP%\%APPNAME%-preuninstall.log" | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really happy with this solution of setting the file name here, since it is also explicitly set in
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to access the log file for the MSI installer somehow?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean accessing it from the CI pipeline? Otherwise no, only by opening the file, I think it's a bit clunky, MSI has "support" for logging but it seems very generic since as you might have seen that we enable logging for MSI Installers via
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's why I'm asking if there is any avenue that we can access
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it could work but it's risky. We can end-up with encoding mismatch, MSI log is usually UTF-16. cmd.exe echo writes in the console codepage (effectively “ANSI”/OEM), so you’ll end up mixing encodings in one file.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A problem to solve for a different PR, but I would really like to see those logged in the same file. Maybe we need to extend the logger to detect the file encoding of an existing log file and change it accordingly? The documentation is a little sparse about what happens when Is the risk for race-condition really there? Would an MSI installer even write to log while the script is running?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To answer this correctly, I think we need to do a lot of testing. I agree something for a different PR. |
||
|
|
||
| echo ==== pre_uninstall start ==== >> "%LOG%" | ||
| echo SCRIPT=%~f0 >> "%LOG%" | ||
| echo CWD=%CD% >> "%LOG%" | ||
| echo INSTDIR=%INSTDIR% >> "%LOG%" | ||
| echo BASE_PATH=%BASE_PATH% >> "%LOG%" | ||
| echo CONDA_EXE=%CONDA_EXE% >> "%LOG%" | ||
| echo PAYLOAD_TAR=%PAYLOAD_TAR% >> "%LOG%" | ||
| "%CONDA_EXE%" --version >> "%LOG%" 2>&1 | ||
| {%- endif %} | ||
|
|
||
| {%- set redir = ' >> "%LOG%" 2>&1' if add_debug else '' %} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| {%- set dump_and_exit = 'type "%LOG%" & exit /b %errorlevel%' if add_debug else 'exit /b %errorlevel%' %} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should always create a log if possible. The log level should just determine what goes into the log. We do have to make sure it gets deleted in the end though.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcoesters thanks for your first set of review comments. I thought I'd respond here first because the current design is due to some limitations I ran into last week, and I think we need to discuss this before I make any additional changes.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how the logger is set up: https://github.com/conda/conda-standalone/blob/00deca6accc6fd0b9dae8346f125f1ad1d107524/src/entry_point.py#L134-L164 So, it should catch all
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just tried it and unfortunately it doesn't add unhandled exceptions to the log file.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we found, that was an incorrect example, but it does work. |
||
|
|
||
| rem Consistency checks | ||
| if not exist "%CONDA_EXE%" ( | ||
| {{ error_block('CONDA_EXE not found: "%CONDA_EXE%"', 10) }} | ||
| ) | ||
| rem Recreate an empty payload tar. This file was deleted during installation but the | ||
| rem MSI installer expects it to exist. | ||
| type nul > "%PAYLOAD_TAR%" | ||
| if errorlevel 1 ( | ||
| {{ error_block('Failed to create "%PAYLOAD_TAR%"', '%errorlevel%') }} | ||
| ) | ||
|
|
||
| "%CONDA_EXE%" constructor uninstall --prefix "%BASE_PATH%"{{ redir }} | ||
| if errorlevel 1 ( {{ dump_and_exit }} ) | ||
|
|
||
| exit /b 0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,75 @@ | ||
| set "INSTDIR=%cd%" | ||
| @echo {{ 'on' if add_debug else 'off' }} | ||
| setlocal | ||
|
|
||
| {%- macro error_block(message, code) -%} | ||
| echo [ERROR] {{ message }} | ||
| {%- if add_debug %} | ||
| >> "%LOG%" echo [ERROR] {{ message }} | ||
| {%- endif %} | ||
| exit /b {{ code }} | ||
| {%- endmacro -%} | ||
|
|
||
| rem Assign INSTDIR and normalize the path | ||
| set "INSTDIR=%~dp0.." | ||
| for %%I in ("%INSTDIR%") do set "INSTDIR=%%~fI" | ||
|
|
||
| set "BASE_PATH=%INSTDIR%\base" | ||
| set "PREFIX=%BASE_PATH%" | ||
| set "CONDA_EXE=%INSTDIR%\{{ conda_exe_name }}" | ||
| set "PAYLOAD_TAR=%INSTDIR%\{{ archive_name }}" | ||
|
|
||
| echo "Unpacking payload..." | ||
| "%CONDA_EXE%" constructor extract --prefix "%INSTDIR%" --tar-from-stdin < "%PAYLOAD_TAR%" | ||
| "%CONDA_EXE%" constructor --prefix "%BASE_PATH%" --extract-conda-pkgs | ||
|
|
||
| set CONDA_EXTRA_SAFETY_CHECKS=no | ||
| set CONDA_PROTECT_FROZEN_ENVS=0 | ||
| set "CONDA_ROOT_PREFIX=%BASE_PATH%" | ||
| set CONDA_REGISTER_ENVS={{ register_envs }} | ||
| set CONDA_SAFETY_CHECKS=disabled | ||
| set CONDA_EXTRA_SAFETY_CHECKS=no | ||
| set "CONDA_ROOT_PREFIX=%BASE_PATH%" | ||
| set "CONDA_PKGS_DIRS=%BASE_PATH%\pkgs" | ||
|
|
||
| "%CONDA_EXE%" install --offline --file "%BASE_PATH%\conda-meta\initial-state.explicit.txt" -yp "%BASE_PATH%" | ||
| {%- if add_debug %} | ||
| rem Get the name of the install directory | ||
| for %%I in ("%INSTDIR%") do set "APPNAME=%%~nxI" | ||
| set "LOG=%TEMP%\%APPNAME%-postinstall.log" | ||
|
|
||
| echo ==== run_installation start ==== >> "%LOG%" | ||
| echo SCRIPT=%~f0 >> "%LOG%" | ||
| echo CWD=%CD% >> "%LOG%" | ||
| echo INSTDIR=%INSTDIR% >> "%LOG%" | ||
| echo BASE_PATH=%BASE_PATH% >> "%LOG%" | ||
| echo CONDA_EXE=%CONDA_EXE% >> "%LOG%" | ||
| echo PAYLOAD_TAR=%PAYLOAD_TAR% >> "%LOG%" | ||
| {%- endif %} | ||
|
|
||
| {%- set redir = ' >> "%LOG%" 2>&1' if add_debug else '' %} | ||
| {%- set dump_and_exit = 'type "%LOG%" & exit /b %errorlevel%' if add_debug else 'exit /b %errorlevel%' %} | ||
|
|
||
| rem Consistency checks | ||
| if not exist "%CONDA_EXE%" ( | ||
| {{ error_block('CONDA_EXE not found: "%CONDA_EXE%"', 10) }} | ||
| ) | ||
| if not exist "%PAYLOAD_TAR%" ( | ||
| {{ error_block('PAYLOAD_TAR not found: "%PAYLOAD_TAR%"', 11) }} | ||
| ) | ||
|
|
||
| echo Unpacking payload... | ||
| rem "%CONDA_EXE%" constructor extract --prefix "%INSTDIR%" --tar-from-stdin < "%PAYLOAD_TAR%"{{ redir }} | ||
| "%CONDA_EXE%" constructor --prefix "%INSTDIR%" --extract-tarball < "%PAYLOAD_TAR%"{{ redir }} | ||
| if errorlevel 1 ( {{ dump_and_exit }} ) | ||
|
|
||
| rem "%CONDA_EXE%" constructor --prefix "%BASE_PATH%" --extract-conda-pkgs{{ redir }} | ||
| "%CONDA_EXE%" constructor --prefix "%BASE_PATH%" --extract-conda-pkgs{{ redir }} | ||
| if errorlevel 1 ( {{ dump_and_exit }} ) | ||
|
|
||
| if not exist "%BASE_PATH%" ( | ||
| {{ error_block('"%BASE_PATH%" not found!', 12) }} | ||
| ) | ||
|
|
||
| "%CONDA_EXE%" install --offline --file "%BASE_PATH%\conda-meta\initial-state.explicit.txt" -yp "%BASE_PATH%"{{ redir }} | ||
| if errorlevel 1 ( {{ dump_and_exit }} ) | ||
|
|
||
| rem Delete the payload to save disk space. | ||
| rem A truncated placeholder of 0 bytes is recreated during uninstall | ||
| rem because MSI expects the file to be there to clean the registry. | ||
| del "%PAYLOAD_TAR%" | ||
| if errorlevel 1 ( {{ dump_and_exit }} ) | ||
|
|
||
| exit /b 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I'll change back to
1later.