[FIX] modules: choose the right addons path
When launching a server with two similar addons path, e.g.: - /home/alice/dev - /home/alice/devodoo launching the server in dev mode may crash due to the poor matching using `path.startswith(...)` method which may make `/home/alice/devodoo/bob/main.xml` match in addons folder `/home/alice/dev` and with a non-exitant local path `odoo/bob/main.xml`. Instead of relying on the name, use the `os.path.commonprefix()` method to match on real paths and avoid partial matching. commonprefix will only work if the folder name ends with the appropriate separator (which is not guarantee for a user provided addons-path) so force a trailing `/` using os.path.join(..., '')`. Closes #12359
This commit is contained in:
@@ -177,9 +177,16 @@ def get_resource_from_path(path):
|
||||
:rtype: tuple
|
||||
:return: tuple(module_name, relative_path, os_relative_path) if possible, else None
|
||||
"""
|
||||
resource = [path.replace(adpath, '') for adpath in ad_paths if path.startswith(adpath)]
|
||||
resource = False
|
||||
for adpath in ad_paths:
|
||||
# force trailing separator
|
||||
adpath = os.path.join(adpath, "")
|
||||
if os.path.commonprefix([adpath, path]) == adpath:
|
||||
resource = path.replace(adpath, "", 1)
|
||||
break
|
||||
|
||||
if resource:
|
||||
relative = resource[0].split(os.path.sep)
|
||||
relative = resource.split(os.path.sep)
|
||||
if not relative[0]:
|
||||
relative.pop(0)
|
||||
module = relative.pop(0)
|
||||
|
||||
Reference in New Issue
Block a user