lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.88k stars 414 forks source link

`lark.Lark` `cache=True` default cache filename can be problematic on multi-user systems #1178

Closed klauer closed 2 years ago

klauer commented 2 years ago

Describe the bug

The default lark.Lark caching mechanism can fail when utilized on a multi-user system with more than one user due to the default permissions of the cached file. (See the traceback/reproduction steps below.)

To Reproduce

...
  File "env_path/python3.9/site-packages/whatrecord/db.py", line 646, in from_string
    grammar = lark.Lark.open_from_package(
  File "env_path/python3.9/site-packages/lark/lark.py", line 566, in open_from_package
    return cls(text, **options)
  File "env_path/python3.9/site-packages/lark/lark.py", line 315, in __init__
    with FS.open(cache_fn, 'rb') as f:
  File "env_path/python3.9/site-packages/lark/utils.py", line 232, in open
    return open(name, mode, **kwargs)
PermissionError: [Errno 13] Permission denied: '/tmp/.lark_cache_bf910f0d49cfefbc0576ce70de8a7dbd_3_9.tmp'

I wonder if the default cache filename format should perhaps also include a username? Read-only permissions for group/other could be okay, too.