|
1 | 1 | import _native |
| 2 | +import time |
2 | 3 |
|
3 | 4 | from .fsutils import rmtree, unlink |
4 | 5 | from .logging import LOGGER |
@@ -47,15 +48,28 @@ def _make(root, prefix, item, allow_warn=True): |
47 | 48 | LOGGER.debug("Path: %s", lnk) |
48 | 49 | LOGGER.debug("Directory: %s", root) |
49 | 50 | return None |
50 | | - _native.shortcut_create( |
51 | | - lnk, |
52 | | - target, |
53 | | - arguments=_unprefix(item.get("Arguments"), prefix), |
54 | | - working_directory=_unprefix(item.get("WorkingDirectory"), prefix) |
55 | | - or _native.shortcut_default_cwd(), |
56 | | - icon=_unprefix(item.get("Icon"), prefix), |
57 | | - icon_index=item.get("IconIndex", 0), |
58 | | - ) |
| 51 | + first_exc = None |
| 52 | + for retry in range(5): |
| 53 | + try: |
| 54 | + _native.shortcut_create( |
| 55 | + lnk, |
| 56 | + target, |
| 57 | + arguments=_unprefix(item.get("Arguments"), prefix), |
| 58 | + working_directory=_unprefix(item.get("WorkingDirectory"), prefix) |
| 59 | + or _native.shortcut_default_cwd(), |
| 60 | + icon=_unprefix(item.get("Icon"), prefix), |
| 61 | + icon_index=item.get("IconIndex", 0), |
| 62 | + ) |
| 63 | + break |
| 64 | + except OSError as ex: |
| 65 | + # No errors are reasonably expected here, so we'll retry for any. |
| 66 | + # So far, all we've observed have been race conditions. |
| 67 | + if not first_exc: |
| 68 | + first_exc = ex |
| 69 | + time.sleep(0.1) |
| 70 | + if first_exc: |
| 71 | + LOGGER.debug("Failed to create shortcut") |
| 72 | + raise first_exc |
59 | 73 | return lnk |
60 | 74 |
|
61 | 75 |
|
|
0 commit comments