这是indexloc提供的服务,不要输入任何密码
Skip to content

Bug: Incorrect path passed to os.makedirs in file.py causing "Permission denied" (Linux) #821

@Heavygrass

Description

@Heavygrass

Hi,
OS Linux.
I made sure the user is correct by adding a few print statements to
/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/cachelib/file.py
right before the line where it crashes.
os.makedirs(self._path) is passed "db/sessions" parameter, which seems to be a relative path?
If yes, relative to what?

I tried to run it in plain Python (under libretranslate user) and it gives the same error:

import os
os.makedirs("db/sessions")    
Traceback (most recent call last):                                                                               
  File "<stdin>", line 1, in <module>                                                                            
  File "<frozen os>", line 215, in makedirs                                                                      
  File "<frozen os>", line 225, in makedirs                                                                      
PermissionError: [Errno 13] Permission denied: 'db' 

Python 3.12.3.

Also set all permissions manually in libretranslate user home dir to libretranslate:libretranslate.

Backtrace (with my print/debug output):
os.makedirs(self._path) originally was at line 80.

~/LibreTranslate/env/bin/libretranslate --load-only en,ru  --host 127.0.0.1                                    
/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/apscheduler/__init__.py:1: UserWarning: pkg_
resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources
 package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.  
  from pkg_resources import get_distribution, DistributionNotFound                                               
                                                                                                                 
 pwd.getpwuid(os.getuid()).pw_name=libretranslate                                                                
self._path=db/sessions                                                                                           
Traceback (most recent call last):                                                                               
  File "/home/libretranslate/LibreTranslate/env/bin/libretranslate", line 8, in <module>                         
    sys.exit(main())                                                                                             
             ^^^^^^                                                                                              
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/libretranslate/main.py", line 258, i
n main                                                                                                           
    app = create_app(args)                                                                                       
          ^^^^^^^^^^^^^^^^                                                                                       
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/libretranslate/app.py", line 1227, i
n create_app                                                                                                     
    Session(app)                                                                                                 
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/flask_session/__init__.py", line 54,
 in __init__                                                                                                     
    self.init_app(app)                                                                                           
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/flask_session/__init__.py", line 61,
 in init_app                                                                                                     
    app.session_interface = self._get_interface(app)                                                             
                            ^^^^^^^^^^^^^^^^^^^^^^^^                                                             
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/flask_session/__init__.py", line 90,
in _get_interface
    session_interface = FileSystemSessionInterface(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/flask_session/sessions.py", line 322
, in __init__
    self.cache = FileSystemCache(cache_dir, threshold=threshold, mode=mode)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/libretranslate/LibreTranslate/env/lib/python3.12/site-packages/cachelib/file.py", line 83, in __ini
t__
    os.makedirs(self._path)
  File "<frozen os>", line 215, in makedirs
  File "<frozen os>", line 225, in makedirs
PermissionError: [Errno 13] Permission denied: 'db'

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions