Get AI-generated vulnerability analysis
()
| 19116 | performs: the browser polls this while the web app itself is down and back. |
| 19117 | |
| 19118 | A run that never reached its end - power cut mid-provision, an apt call that |
| 19119 | hung, the transient unit killed - leaves 'running' in the file forever. |
| 19120 | Reported as-is that pinned the update card on a step from an update that |
| 19121 | finished days ago ("Finishing update: network tools...") and made every later |
| 19122 | verification wait for a step that would never complete. Past the staleness |
| 19123 | window the file is treated as the debris it is. |
| 19124 | """ |
| 19125 | try: |
| 19126 | with open(_POST_UPDATE_STATUS_PATH, 'r') as fh: |
| 19127 | status = json.load(fh) |
| 19128 | except (OSError, ValueError): |
| 19129 | return {} |
| 19130 | if not isinstance(status, dict): |
| 19131 | return {} |
| 19132 | |
| 19133 | if status.get('state') == 'running': |
| 19134 | try: |
| 19135 | age = time.time() - os.path.getmtime(_POST_UPDATE_STATUS_PATH) |
| 19136 | except OSError: |
| 19137 | age = 0 |
| 19138 | if age > _POST_UPDATE_STALE_SECONDS: |
| 19139 | logger.warning("Ignoring post-update status stuck at " |
| 19140 | f"'{status.get('step', '?')}' for {int(age // 60)} minutes") |
| 19141 | return {'state': 'finished', 'outcome': 'unknown', 'step': status.get('step', ''), |
| 19142 | 'stale': True, |
| 19143 | 'failures': 'the previous post-update run never finished; ' |
| 19144 | 'see data/logs/post_update.log'} |
| 19145 | return status |
| 19146 | |
| 19147 | |
| 19148 | def _reset_post_update_status() -> None: |
| 19149 | """Drop the previous run's status before starting a new one. |
| 19150 | |
| 19151 | Without this the first polls of a new update report the *last* update's |
| 19152 | step, because post_update.sh cannot write its own until it has started. |
| 19153 | """ |
| 19154 | try: |
| 19155 | os.remove(_POST_UPDATE_STATUS_PATH) |
| 19156 | except OSError: |
| 19157 | pass |
nothing calls this directly
no test coverage detected