diff mbox series

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

Message ID 20221212174349.714152-1-lautrbach@redhat.com (mailing list archive)
State Accepted
Commit 7ff1d7f1c2a1
Headers show
Series sepolicy: Call os.makedirs() with exist_ok=True | expand

Commit Message

Petr Lautrbach Dec. 12, 2022, 5:43 p.m. UTC
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/'

Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
---
 python/sepolicy/sepolicy/manpage.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

James Carter Dec. 16, 2022, 9:24 p.m. UTC | #1
On Mon, Dec 12, 2022 at 12:49 PM Petr Lautrbach <lautrbach@redhat.com> wrote:
>
> 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/'
>
> Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  python/sepolicy/sepolicy/manpage.py | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
> index edeb3b77e759..1bff8f9acb49 100755
> --- a/python/sepolicy/sepolicy/manpage.py
> +++ b/python/sepolicy/sepolicy/manpage.py
> @@ -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
>
James Carter Dec. 16, 2022, 10:02 p.m. UTC | #2
On Fri, Dec 16, 2022 at 4:24 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, Dec 12, 2022 at 12:49 PM Petr Lautrbach <lautrbach@redhat.com> wrote:
> >
> > 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/'
> >
> > Signed-off-by: Petr Lautrbach <lautrbach@redhat.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>

Merged.
Thanks,
Jim

>
> > ---
> >  python/sepolicy/sepolicy/manpage.py | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
> > index edeb3b77e759..1bff8f9acb49 100755
> > --- a/python/sepolicy/sepolicy/manpage.py
> > +++ b/python/sepolicy/sepolicy/manpage.py
> > @@ -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
> >
diff mbox series

Patch

diff --git a/python/sepolicy/sepolicy/manpage.py b/python/sepolicy/sepolicy/manpage.py
index edeb3b77e759..1bff8f9acb49 100755
--- a/python/sepolicy/sepolicy/manpage.py
+++ b/python/sepolicy/sepolicy/manpage.py
@@ -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