Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork938
Commit9e5d0aa
committed
Avoid subprocess-writable temp file race condition
This lets the Windows subprocess open or rename onto the temporaryfile using a more robust approach than inb12fd4a, avoiding therace condition described there, where the filename could beinadvertently reused between deletion and recreation of the file.This creates a context manager helper for the temporary index fileused in IndexFile.from_tree, whose implementation differs byoperating system:- Delegating straightforwardly to NamedTempoaryFile on POSIX systems where an open file can replaced by having another file renamed to it (just as it can be deleted).- Employing custom logic on Windows, using mkstemp, closing the temporary file without immediately deleting it (so it won't be reused by any process seeking to create a temporary file), and then deleting it on context manager exit.IndexFile.from_tree now calls this helper instead ofNamedTemporaryFile. For convenience, the helper provides the path,i.e. the "name", when entered, so tmp_index is now just that path.(At least for now, this helper is implemented as a nonpublicfunction in the git.index.base module, rather than in thegit.index.util module. If it were public in git.index.util like theother facilities there, then some later changes to it, or its laterremoval, would be a breaking change to GitPython. If it werenonpublic in git.index.util, then this would not be a concern, butit would be unintuitive for it to be accessed from code in thegit.index.base module. In the future, one way to address this mightbe to have one or more nonpublic _util modules with public members.Because it would still be a breaking change to drop existing publicutil modules, that would be more utility modules in total, so sucha change isn't included here just for this one used-once function.)1 parent928ca1e commit9e5d0aa
1 file changed
+27
-7
lines changedLines changed: 27 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
9 |
| - | |
| 9 | + | |
10 | 10 |
| |
11 | 11 |
| |
12 | 12 |
| |
| |||
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
| 70 | + | |
70 | 71 |
| |
71 | 72 |
| |
72 | 73 |
| |
| |||
96 | 97 |
| |
97 | 98 |
| |
98 | 99 |
| |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
99 | 121 |
| |
100 | 122 |
| |
101 | 123 |
| |
| |||
359 | 381 |
| |
360 | 382 |
| |
361 | 383 |
| |
362 |
| - | |
363 |
| - | |
364 |
| - | |
365 |
| - | |
366 |
| - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
367 | 387 |
| |
368 | 388 |
| |
369 | 389 |
| |
| |||
373 | 393 |
| |
374 | 394 |
| |
375 | 395 |
| |
376 |
| - | |
| 396 | + | |
377 | 397 |
| |
378 | 398 |
| |
379 | 399 |
| |
|
0 commit comments
Comments
(0)