Skip to content

Commit

Permalink
Merge pull request #110 from jumpstarter-dev/dutlink-storage
Browse files Browse the repository at this point in the history
dutlink: use better method for detecting storage media presence
  • Loading branch information
NickCao authored Oct 4, 2024
2 parents e00148f + d4c2361 commit 1fbeff7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions contrib/dutlink/jumpstarter_driver_dutlink/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1fbeff7

Please sign in to comment.