devices: new helper to ensure a device node exists
Add a new `ensure_device_node` helper function that will create the specified device not, if it does not yet exist.
This commit is contained in:
parent
5219e96536
commit
8abed7677f
1 changed files with 10 additions and 0 deletions
|
|
@ -13,12 +13,15 @@ support in osbuild itself is abstract.
|
|||
"""
|
||||
|
||||
import abc
|
||||
import errno
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import stat
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from osbuild import host
|
||||
from osbuild.util import ctx
|
||||
|
||||
|
||||
class Device:
|
||||
|
|
@ -95,6 +98,13 @@ class DeviceManager:
|
|||
class DeviceService(host.Service):
|
||||
"""Device host service"""
|
||||
|
||||
@staticmethod
|
||||
def ensure_device_node(path, major: int, minor: int, dir_fd=None):
|
||||
"""Ensure that the specified device node exists at the given path"""
|
||||
mode = 0o666 | stat.S_IFBLK
|
||||
with ctx.suppress_oserror(errno.EEXIST):
|
||||
os.mknod(path, mode, os.makedev(major, minor), dir_fd=dir_fd)
|
||||
|
||||
@abc.abstractmethod
|
||||
def open(self, devpath: str, parent: str, tree: str, options: Dict):
|
||||
"""Open a specific device
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue