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 Windows compatibility #3

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft

Conversation

amotl
Copy link
Contributor

@amotl amotl commented Dec 19, 2021

Dear Mathias,

CrateDB build #4567182253, triggered by crate/crate#11994, revealed a Windows compatibility issue with wacklig-uploader, it looks like:

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpsu6qtmys'

The reason is that Windows places an exclusive lock on files opened for writing [1]. So, opening the temporary tarfile twice (once by NamedTemporaryFile and another time by tarfile.open(fd.name) makes things croak with PermissionError: [Errno 13] Permission denied.

Instead, with this patch, the file handle already opened by NamedTemporaryFile will be reused for writing to [2].

At wacklig-uploader build #4574519892, we have been able to verify it with a corresponding test case, added with 1f84ee6. Now, Windows compatibility has been added with dedd122, wacklig-uploader build #4575000733 demonstrates it.

The baseline test harness to reveal and mitigate this issue has been added with a previous patch set submitted as #2, where this patch is based upon.

With kind regards,
Andreas.

[1] https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file
[2] https://stackoverflow.com/questions/15857792/how-to-construct-a-tarfile-object-in-memory-from-byte-buffer-in-python-3

@amotl amotl mentioned this pull request Dec 19, 2021
@amotl amotl marked this pull request as draft December 19, 2021 17:16
amotl added 10 commits December 19, 2021 18:18
Now, `jenkins_env` and `github_action_env` will only be tested through
`get_ci_info`. That is the main adapter function anyway.
This is just a minor fix for the test suite to adjust path semantics for
Windows, which uses backslashes as directory separators instead of slashes.
Actually, the `test_upload_files_success` test should have revealed it.
However, we discovered that when mocking the `NamedTemporaryFile`
object, we created an instance instead of propagating a factory.

That is wrong, because it expands the scope of the temporary file to
the whole test case, and not the scope of the `test_upload_files`
function only.
Apparently, mocking `urllib.urlopen()` will not trigger the flaw within
a test case on Windows.

So, let's use a different strategy by mocking the socket object instead.
In this manner, the whole machinery of `urllib` and `http.client` will
still be active, hopefully revealing the incompatibility with Windows.
Windows places an exclusive lock on files opened for writing. So,
opening the temporary tarfile twice (once by `NamedTemporaryFile` and
another time by `tarfile.open(fd.name)` makes things croak with
`PermissionError: [Errno 13] Permission denied`.

Instead, let's reuse the file handle already opened by
`NamedTemporaryFile`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant