Skip to contentSkip to conversation

sepolicy: Call os.makedirs() with exist_ok=True

PATCH In review Petr Lautrbach 2 participants 3 messages Dec 12, 2022 – Dec 16, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sepolicy: Call os.makedirs() with exist_ok=True

Since commit 7494bb1298b3 ("sepolicy: generate man pages in parallel") man pages are generated in parallel and there's a race between os.path.exists() and os.makedirs().

The check os.path.exists() is not necessary when os.makedirs() is called with exist_ok=True.

Fixes:
/usr/bin/sepolicy manpage -a -p /__w/usr/share/man/man8/ -w -r /__w/
FileExistsError: [Errno 17] File exists: '/__w/usr/share/man/man8/'

---
 python/sepolicy/sepolicy/manpage.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
python/sepolicy/sepolicy/manpage.py +1 -2
index edeb3b77e759..1bff8f9acb49 100755
@@ -376,8 +376,7 @@ class ManPage:
 
         self.fcdict = sepolicy.get_fcdict(self.fcpath)
 
-        if not os.path.exists(path):
-            os.makedirs(path)
+        os.makedirs(path, exist_ok=True)
 
         self.path = path
 
Signature · 1 line
2.38.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Petr Lautrbach

Since commit 7494bb1298b3 ("sepolicy: generate man pages in parallel") man pages are generated in parallel and there's a race between os.path.exists() and os.makedirs().

Quoted 8 lines

The check os.path.exists() is not necessary when os.makedirs() is called with exist_ok=True.

Fixes:
/usr/bin/sepolicy manpage -a -p /__w/usr/share/man/man8/ -w -r /__w/
FileExistsError: [Errno 17] File exists: '/__w/usr/share/man/man8/'

Quoted 21 lines
---
 python/sepolicy/sepolicy/manpage.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
python/sepolicy/sepolicy/manpage.py +1 -3
index edeb3b77e759..1bff8f9acb49 100755
@@ -376,8 +376,7 @@ class ManPage:
 
         self.fcdict = sepolicy.get_fcdict(self.fcpath)
 
-        if not os.path.exists(path):
-            os.makedirs(path)
+        os.makedirs(path, exist_ok=True)
 
         self.path = path
 
--

2.38.1

#2 lore raw
Quoted 10 lines · James Carter
Quoted 8 lines · Petr Lautrbach

Since commit 7494bb1298b3 ("sepolicy: generate man pages in parallel") man pages are generated in parallel and there's a race between os.path.exists() and os.makedirs().

The check os.path.exists() is not necessary when os.makedirs() is called with exist_ok=True.

Quoted 7 lines
Quoted 5 lines

Fixes:
/usr/bin/sepolicy manpage -a -p /__w/usr/share/man/man8/ -w -r /__w/
FileExistsError: [Errno 17] File exists: '/__w/usr/share/man/man8/'

Merged.
Thanks,
Jim

Quoted 22 lines
Quoted 22 lines
---
 python/sepolicy/sepolicy/manpage.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
python/sepolicy/sepolicy/manpage.py +1 -3
index edeb3b77e759..1bff8f9acb49 100755
@@ -376,8 +376,7 @@ class ManPage:
 
         self.fcdict = sepolicy.get_fcdict(self.fcpath)
 
-        if not os.path.exists(path):
-            os.makedirs(path)
+        os.makedirs(path, exist_ok=True)
 
         self.path = path
 
--

2.38.1