[swugenerator][PATCH 1/2] Guard POSIX-specific os functions

21 views
Skip to first unread message

Bastian Germann

unread,
Aug 7, 2026, 7:45:28 AMAug 7
to swup...@googlegroups.com, Bastian Germann
For non-POSIX systems, make it possible to shortcut the os.major and
os.minor functions. The alternatives stat.major and stat.minor are not
available with Python 3.14 anymore.

Signed-off-by: Bastian Germann <ba...@debian.org>
---
swugenerator/swu_file.py | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/swugenerator/swu_file.py b/swugenerator/swu_file.py
index 126e0d1..05ba486 100644
--- a/swugenerator/swu_file.py
+++ b/swugenerator/swu_file.py
@@ -18,6 +18,16 @@ class MagicException(Exception):
class FormatException(Exception):
pass

+def _major(device):
+ if device == 0:
+ return 0
+ return os.major(device)
+
+def _minor(device):
+ if device == 0:
+ return 0
+ return os.minor(device)
+
class SWUFile:
def __init__(self, file):
"""
@@ -108,10 +118,10 @@ class SWUFile:
statres.st_nlink,
0, # mtime
statres.st_size,
- os.major(statres.st_dev),
- os.minor(statres.st_dev),
- os.major(statres.st_rdev),
- os.minor(statres.st_rdev),
+ _major(statres.st_dev),
+ _minor(statres.st_dev),
+ _major(statres.st_rdev),
+ _minor(statres.st_rdev),
# Yes, length including last zero byte
len(base_filename) + 1,
# New CRC Format

Bastian Germann

unread,
Aug 7, 2026, 7:45:29 AMAug 7
to swup...@googlegroups.com, Bastian Germann
Fixes: #17
Signed-off-by: Bastian Germann <ba...@debian.org>
---
swugenerator/swu_file.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/swugenerator/swu_file.py b/swugenerator/swu_file.py
index 05ba486..2f0f0bd 100644
--- a/swugenerator/swu_file.py
+++ b/swugenerator/swu_file.py
@@ -110,6 +110,8 @@ class SWUFile:
statres = os.stat(cpio_filename)
crc = self.cpiocrc(cpio_filename)
base_filename = os.path.basename(cpio_filename)
+ st_dev = statres.st_dev if os.name == "posix" else 0
+ st_rdev = statres.st_rdev if os.name == "posix" else 0
fields = [
self.next_renumbered_inode(),
statres.st_mode,
@@ -118,10 +120,10 @@ class SWUFile:
statres.st_nlink,
0, # mtime
statres.st_size,
- _major(statres.st_dev),
- _minor(statres.st_dev),
- _major(statres.st_rdev),
- _minor(statres.st_rdev),
+ _major(st_dev),
+ _minor(st_dev),
+ _major(st_rdev),
+ _minor(st_rdev),

Stefano Babic

unread,
Aug 10, 2026, 4:06:54 AMAug 10
to Bastian Germann, swup...@googlegroups.com
Applied to -master, thanks !

Best regards,
Stefano

--
_______________________________________________________________________
Nabla Software Engineering GmbH
Hirschstr. 111A | 86156 Augsburg | Tel: +49 821 45592596
Geschäftsführer : Stefano Babic | HRB 40522 Augsburg
E-Mail: sba...@nabladev.com

Stefano Babic

unread,
Aug 10, 2026, 4:07:11 AMAug 10
to Bastian Germann, swup...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages