forslund / combo-lock

Apache License 2.0
4 stars 1 forks source link

Update util.py #13

Closed JarbasAl closed 2 years ago

JarbasAl commented 2 years ago

fix potential race condition if directory is created by external process after evaluation of the condition but before the path creation

this is a hard one to trigger, but was reported in ovos chat

==> logs/audio.log <==
2022-10-02 21:39:17.551 - OVOS - ovos_utils.configuration:<module>:52 - WARNING - configuration moved to the `ovos_config` package. This submodule will be removed in ovos_utils 0.1.0

[Errno 17] File exists: '/run/user/1000/combo_locks'
Traceback (most recent call last):
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/combo_lock.py", line 100, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/util.py", line 9, in get_ram_directory
    os.makedirs(path)
  File "/usr/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/run/user/1000/combo_locks'
goldyfruit commented 2 years ago

14

goldyfruit commented 2 years ago

Tested and got a different error:

==> logs/bus.log <==
makedirs() got an unexpected keyword argument 'exists_ok'
Traceback (most recent call last):
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/combo_lock.py", line 100, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/util.py", line 8, in get_ram_directory
    os.makedirs(path, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

==> logs/voice.log <==
makedirs() got an unexpected keyword argument 'exists_ok'
Traceback (most recent call last):
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/combo_lock.py", line 100, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/util.py", line 8, in get_ram_directory
    os.makedirs(path, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

==> logs/audio.log <==
makedirs() got an unexpected keyword argument 'exists_ok'
Traceback (most recent call last):
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/combo_lock.py", line 100, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/util.py", line 8, in get_ram_directory
    os.makedirs(path, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

==> logs/skills.log <==
makedirs() got an unexpected keyword argument 'exists_ok'
Traceback (most recent call last):
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/combo_lock.py", line 100, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/util.py", line 8, in get_ram_directory
    os.makedirs(path, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'

==> logs/bus.log <==
2022-10-02 21:53:24.645 - OVOS - __main__:main:45 - INFO - Starting message bus service...
2022-10-02 21:53:24.647 - OVOS - mycroft.messagebus.load_config:load_message_bus_config:33 - INFO - Loading message bus configs
2022-10-02 21:53:24.658 - OVOS - __main__:on_ready:33 - INFO - Message bus service started!

==> logs/enclosure.log <==
makedirs() got an unexpected keyword argument 'exists_ok'
Traceback (most recent call last):
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/combo_lock.py", line 100, in __init__
    path = join(get_ram_directory("combo_locks"), filename)
  File "/home/snow/ovos/lib/python3.9/site-packages/combo_lock/util.py", line 8, in get_ram_directory
    os.makedirs(path, exists_ok=True)
TypeError: makedirs() got an unexpected keyword argument 'exists_ok'
forslund commented 2 years ago

Nice change, this seems much cleaner, I took the liberty to squash the typo-commit and reword the commit message to have a more descriptive first line. Merging