mhammond / pywin32

Python for Windows (pywin32) Extensions
4.9k stars 783 forks source link

Perform file move of pythonservice.exe during install #2251

Open JacobNolan1 opened 2 months ago

JacobNolan1 commented 2 months ago

During install perform move of pythonservice.exe instead of file copy to handle .exe always being present in src location.

Additional try-except added to handle continuation of program if fileMove fails.

JacobNolan1 commented 2 months ago

Attempted a build to test this, but wasn't successful. Was missing a couple dlls and haven't managed to track down why I don't have them yet.

mhammond commented 2 months ago

Thanks - note if you go to "checks" and dig around you can find artifacts for your PR - in this case it is at https://github.com/mhammond/pywin32/actions/runs/8890105083?pr=2251

JacobNolan1 commented 2 months ago

Awesome thanks Mark. This sorted my issue. I may change the exception output "Failed to move host exe" in the case where the file already exists, it did deceive me for a moment there thinking the process failed completely.

The current error output from MoveFile is "Cannot create a file when file already exists". So I think in this case, where the destination file is still used, MoveFile does fail to replace. Which makes sense.

The install does work regardless if pythonservice.exe is present in the destination dir.

mhammond commented 2 months ago

It's important that the move replace the file - if the source file exists it implies pywin32 has been upgraded so the existing target may not work. MoveFileEx should offer the semantics you needs.