Skip to content

Commit

Permalink
Add compatibility with Windows
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
amotl committed Dec 19, 2021
1 parent 5c84fa4 commit f795774
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Tests: Run test harness on GHA
- Tests: Add Windows to test matrix on CI/GHA
- Tests: Fix tests on Windows
- Add compatibility with Windows regarding exclusive write-lock
at `NamedTemporaryFile` vs. `tarfile.open`


## 0.3.0 (2021-07-01)
Expand Down
3 changes: 2 additions & 1 deletion wacklig.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ def upload_files(token, server, ci_info, files):
raise SystemExit('No test files found')
ci_info['token'] = token
with tempfile.NamedTemporaryFile() as fd:
with tarfile.open(fd.name, 'w:gz') as tar:
with tarfile.open(fileobj=fd, mode='w:gz') as tar:
for filename in files:
tar.add(filename)
fd.seek(0)
ci_info = {k: v for (k, v) in ci_info.items() if v}
params = ci_info and '?' + urlencode(ci_info) or ''
result = urlopen(server + '/api/v1/upload' + params, data=fd)
Expand Down

0 comments on commit f795774

Please sign in to comment.