diff --git a/fix-no_device_md0_fault.patch b/fix-no_device_md0_fault.patch new file mode 100644 index 0000000000000000000000000000000000000000..cc2002262102249da3a2ff4f29ad7f8a99c0c0f8 --- /dev/null +++ b/fix-no_device_md0_fault.patch @@ -0,0 +1,95 @@ +From 4d05ba2b009d2118ee54f33be3d2b80c5e44cd45 Mon Sep 17 00:00:00 2001 +From: Chuan Li +Date: Tue, 8 Jul 2025 16:22:17 +0800 +Subject: [PATCH] fix kp920 md0 not found error + +--- + src/pyudev/device/_device.py | 59 +++++++++++++++++++++++++++++++++++- + 1 file changed, 58 insertions(+), 1 deletion(-) + +diff --git a/src/pyudev/device/_device.py b/src/pyudev/device/_device.py +index db6b90c..ed76db4 100644 +--- a/src/pyudev/device/_device.py ++++ b/src/pyudev/device/_device.py +@@ -28,7 +28,13 @@ import collections + import os + import re + import sys ++import time + from datetime import timedelta ++import ctypes ++from pyudev._ctypeslib.libudev import ERROR_CHECKERS, SIGNATURES ++from pyudev._ctypeslib.utils import load_ctypes_library ++from pyudev._util import ensure_byte_string, udev_list_iterate ++from pyudev._errors import DeviceNotFoundAtPathError + + # isort: LOCAL + from pyudev._errors import ( +@@ -104,8 +110,19 @@ class Devices(object): + device = context._libudev.udev_device_new_from_syspath( + context, ensure_byte_string(sys_path) + ) ++ + if not device: +- raise DeviceNotFoundAtPathError(sys_path) ++ time.sleep(2) ++ block_device_pathes = list_block_device_sys_paths() ++ if block_device_pathes: ++ for path in block_device_pathes: ++ if path == sys_path: ++ raise DeviceNotFoundAtPathError(sys_path) ++ else: ++ continue ++ return None ++ else: ++ raise DeviceNotFoundAtPathError(sys_path) + return Device(context, device) + + @classmethod +@@ -1293,3 +1310,43 @@ class Tags(collections.abc.Iterable, collections.abc.Container): + tags = self._libudev.udev_device_get_tags_list_entry(self.device) + for tag, _ in udev_list_iterate(self._libudev, tags): + yield ensure_unicode_string(tag) ++ ++def list_block_device_sys_paths(): ++ # Load the udev library ++ libudev = load_ctypes_library("udev", SIGNATURES, ERROR_CHECKERS) ++ ++ # Create a new udev context ++ udev_context = libudev.udev_new() ++ if not udev_context: ++ raise RuntimeError("Failed to create udev context") ++ ++ try: ++ # Create a new udev enumerator ++ enumerator = libudev.udev_enumerate_new(udev_context) ++ if not enumerator: ++ raise RuntimeError("Failed to create udev enumerator") ++ ++ try: ++ # Add match for block subsystem ++ libudev.udev_enumerate_add_match_subsystem(enumerator, ensure_byte_string("block")) ++ ++ # Scan devices ++ libudev.udev_enumerate_scan_devices(enumerator) ++ ++ # Get the list of devices ++ entry = libudev.udev_enumerate_get_list_entry(enumerator) ++ for name, _ in udev_list_iterate(libudev, entry): ++ try: ++ # Create a new Device object for each device ++ device = libudev.udev_device_new_from_syspath(udev_context, ensure_byte_string(name)) ++ if device: ++ # Yield the sys_path instead of the Device object ++ yield ensure_byte_string(libudev.udev_device_get_syspath(device)) ++ except DeviceNotFoundAtPathError: ++ continue ++ finally: ++ # Free the enumerator ++ libudev.udev_enumerate_unref(enumerator) ++ finally: ++ # Free the udev context ++ libudev.udev_unref(udev_context) +-- +2.46.0 + diff --git a/python-pyudev.spec b/python-pyudev.spec index e66e28c31694d66e961116a9c2cedcf9ae919fc4..60590db8328c357ec06aa50234f4b71ca2fb13e4 100644 --- a/python-pyudev.spec +++ b/python-pyudev.spec @@ -1,13 +1,15 @@ %global _empty_manifest_terminate_build 0 Name: python-pyudev Version: 0.24.1 -Release: 2 +Release: 3 Summary: A libudev binding License: LGPL 2.1+ URL: http://pyudev.readthedocs.org/ Source0: https://files.pythonhosted.org/packages/20/b6/16961ac3575575260c72928f17df9c99c2a696871e486965ec6e2fa2aff4/pyudev-0.24.1.tar.gz BuildArch: noarch +patch6001: fix-no_device_md0_fault.patch + %description This package supports almost all libudev functionality.The lisence is LGPL.It is a python 2/3 binding to libudev which is a linux @@ -91,6 +93,9 @@ pytest -v --ignore=./tests/test_device.py --ignore=./tests/test_core.py --ignore %{_docdir}/* %changelog +* Fri Aug 08 2025 dillon chen - 0.24.3-3 +- fix no device md0 fault + * Thu May 09 2024 wangxiaomeng - 0.24.1-2 - Fix changlog version