Commit eb36294
authored
[empath-split] Fix --preserve-manifest option (#25637)
`--preserve-manifest` was doing the opposite of what it meant to do:
deleting the manifest file when `--preserve-manifest` was given and not
deleting it when it was not given.
But simply changing
```py
with tempfile.NamedTemporaryFile(suffix=".manifest", mode='w+', delete=args.preserve_manifest) as f:
```
```py
with tempfile.NamedTemporaryFile(suffix=".manifest", mode='w+', delete=not args.preserve_manifest) as f:
```
doesn't work, because of Windows' peculiar behavior.
It looks in Windows it is not allowed to re-open an already opened file
unless some conditions are met:
https://docs.python.org/3/library/tempfile.html
> Opening the temporary file again by its name while it is still open
works as follows:
> - On POSIX the file can always be opened again.
> - On Windows, make sure that at least one of the following conditions
are fulfilled:
> - `delete` is false
> - additional open shares delete access (e.g. by calling
[os.open()](https://docs.python.org/3/library/os.html#os.open) with the
flag `O_TEMPORARY`)
> - `delete` is true but `delete_on_close` is false. Note, that in this
case the additional opens that do not share delete access (e.g. created
via builtin
[open()](https://docs.python.org/3/library/functions.html#open)) must be
closed before exiting the context manager, else the
[os.unlink()](https://docs.python.org/3/library/os.html#os.unlink) call
on context manager exit will fail with a
[PermissionError](https://docs.python.org/3/library/exceptions.html#PermissionError).
And we are trying to reopen a temporary file within the `with` context.
The Windows CI didn't error out before this PR because the first
condition (`delete` is false) was accidentally satisfied due to this
bug. To fix this I think we can't help but use `try`-`finally`.1 parent d574f69 commit eb36294
2 files changed
+21
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15183 | 15183 | | |
15184 | 15184 | | |
15185 | 15185 | | |
15186 | | - | |
| 15186 | + | |
| 15187 | + | |
15187 | 15188 | | |
15188 | 15189 | | |
15189 | 15190 | | |
| |||
15207 | 15208 | | |
15208 | 15209 | | |
15209 | 15210 | | |
| 15211 | + | |
| 15212 | + | |
| 15213 | + | |
| 15214 | + | |
| 15215 | + | |
| 15216 | + | |
| 15217 | + | |
| 15218 | + | |
| 15219 | + | |
| 15220 | + | |
| 15221 | + | |
| 15222 | + | |
15210 | 15223 | | |
15211 | 15224 | | |
15212 | 15225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
318 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
319 | 320 | | |
320 | 321 | | |
321 | 322 | | |
| |||
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
342 | | - | |
| 343 | + | |
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
| |||
349 | 350 | | |
350 | 351 | | |
351 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
352 | 356 | | |
353 | 357 | | |
354 | 358 | | |
| |||
0 commit comments