From d4c23613e44464e5047b4abb8d8c4a50b2ade1a4 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Fri, 4 Oct 2024 13:48:33 -0400 Subject: [PATCH] dutlink: use better method for detecting storage media presence --- .../dutlink/jumpstarter_driver_dutlink/driver.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/contrib/dutlink/jumpstarter_driver_dutlink/driver.py b/contrib/dutlink/jumpstarter_driver_dutlink/driver.py index 9b409669..12d7d946 100644 --- a/contrib/dutlink/jumpstarter_driver_dutlink/driver.py +++ b/contrib/dutlink/jumpstarter_driver_dutlink/driver.py @@ -3,7 +3,6 @@ import os from collections.abc import AsyncGenerator from dataclasses import dataclass, field -from pathlib import Path import pyudev import usb.core @@ -94,13 +93,13 @@ async def write(self, src: str): with fail_after(20): while True: if os.path.exists(self.storage_device): + # https://stackoverflow.com/a/2774125 + fd = os.open(self.storage_device, os.O_WRONLY) try: - Path(self.storage_device).write_bytes(b"\0") - except OSError: - pass # wait for device ready - else: - break - + if os.lseek(fd, 0, os.SEEK_END) > 0: + break + finally: + os.close(fd) await sleep(1) async with await FileWriteStream.from_path(self.storage_device) as stream: